Re: Make Nim easier for the developer

2019-10-28 Thread AMoura
The word "popular" is maybe a bad word and I can understand that somebody can 
disagree with it.

@edu500ac, you are passionate of Lisp and I understand that you are heap up 
when a guy say that a good language is a popular language. Lisp is certainly a 
good language and as you say lot of great applications or libraries was 
developed with it. But I'm an industrial developer and I create architecture 
and develop code for embedded board where the performance and an perfect memory 
management is primordial. We use C/C++ and my scientist co-workers use MatLab 
and Python to develop and test algorithm quickly. And my clients need code in C 
and C++ especially when your program must works in autonomous car or in a space 
robot like ExoMars. Then yes, COBOL, Fortran, Pascal etc are maybe great 
languages but they don't support all platforms or architectures and few people 
know them in my field of work.

Languages change, evolve and sometime disappear, now CNRS use Python instead of 
Scilab/Matlab to make scientific algorithms and some big companies (Electronic 
Arts, Red Hat) use RUST instead of C++. Why not Nim ? I like Nim because I can 
write easily my code and it offers me the capability to use my libraries in C++ 
in my personal project. Maybe one day in my work or never.

Thank you @mratsim for nimterop, I'll try it with OpenCV. Use GDB in Windows in 
not a solution because when I work on Windows then I use the Visual C++ 
compiler and never mingw. Yes only 3 paid full-time developers working on Nim 
and it's pity but I prefer this rather than a big company behind a language 
like Sun with Java.


Re: Make Nim easier for the developer

2019-10-28 Thread Stefan_Salewski
> wrapper free interop

Can that really work? Do zig, jai, vlang and all the other new candidates have 
high level gtk support at least, or C++ support for Qt, CGAL, BOOST? I don't 
think so.

For zig it may work for C, as zig does manually memory management, and as zig 
is basically a C better only.

My impression is that even Go is struggling with GTK, and Rust has put very 
much effort in GTK bindings.

And for which languages are really good Qt bindings available? I think only C++ 
and Python has full support.

For a high level language like Nim it is always hard, as Nim has automatic 
memory management, and as C interfaces are not well defined by header files -- 
is that *char a single string or a string array, is it in, out, who frees the 
memory.


Re: Make Nim easier for the developer

2019-10-28 Thread mantielero
I think the comment is more related with [wrapper-free 
interop](https://github.com/nim-lang/Nim/issues/8327) like in [zig 
lang](https://ziglang.org/#Integration-with-C-libraries-without-FFIbindings).

For people like me (mere human -no pro-dev- ;oP ), a feature like this would 
make plenty of libraries suddenly accesible. I have tried (and failed) to wrap 
a few libs myself.

I agree that nimterop and company are great and that they are becoming even 
better. But it would be really nice not needing them.


Re: Make Nim easier for the developer

2019-10-27 Thread edu500ac
Hi, AMoura, thats me again. I think that the main problem with computer 
languages is not lack of features. My major concern about computer languages is 
that most of them do not keep backward compatibility. I liked the _Yi_ text 
editor, which happened to be written in Haskell. Do you know why I quit using 
the _Yi_ editor? Because I could not compile it anymore.

There are many pieces of software around that people stopped using simply 
because developers were not able to build the applications anymore. Consider 
the Daisy Model, which is so important in The Gaia Hypothesis and _global warm 
studies_. I wrote to the author, and he sent me the source code in Basic. The 
difficulty is that no Basic compiler available can build the thing.

Lisp is not a popular language by any means. However, there are many impressive 
Lisp applications. Here is a short list:

1 -- ACL2 -- a system developed by Boyer and Moore to prove the correction of 
hardware and applications. It is one of the most impressive programs that I 
know:

[http://www.cs.utexas.edu/users/moore/acl2](http://www.cs.utexas.edu/users/moore/acl2)/

2 -- Maxima, Computer Algebra System:

[http://maxima.sourceforge.net](http://maxima.sourceforge.net)/

3 -- PTC Creo CAD/CAM allows you to design and manufacture from clothes and 
shoes to complex machines. It seems that the Jarvis butler in the film Iron Man 
was inspired on PTC. My students have a complimentary copy of PTC and, believe 
me, the thing is amazing, specially the programs in Lisp. Here is a link:

[https://www.ptc.com/en/products/cad/creo](https://www.ptc.com/en/products/cad/creo)

4 -- PVS. You probably saw PVS in the film The Marcian. Yes, that strange 
language that appears in the film is Lisp, doped with an overdose of macros:

[https://imgur.com/NMPu7RT](https://imgur.com/NMPu7RT)/

[https://github.com/nasa/pvslib/blob/master/power/exponentiation_aux.prf](https://github.com/nasa/pvslib/blob/master/power/exponentiation_aux.prf)

5 -- Cyc is probably the most accomplished Artificial Intelligence program ever:

[https://www.cyc.com](https://www.cyc.com)/

The list could go on and on, Mirai, Orbitz, Robot Motion Grammar, Biobike, 
Grammarly, Scream, Dendral, ... How could Lisp programmers write such beautiful 
pieces of software? I have a theory: They had time. Simple as that, they have 
time. Lisp programmers took years to create Cyc and Maxima. Such a lengthy 
effort was possible because Lisp does not change with time. You can still use 
the very Lisp programs that Svyatoslav Lavrov and Rifat Appazov used to launch 
artificial satellites and interplanetary probes.

What about Nim? I believe that Lisp does not become obsolete due to its high 
content of Mathematics. As you probably noticed, Mathematics does not change 
either. When I was a student at Cornell, my professor of Mathematics used a 
book written by Gauss, and except for being written in Latin, the book was by 
no means obsolete. Mathematics is optimized, it has a minimum of entities. 
Optimization is minimizing or maximizing a utility function. Lisp grammar is 
the smallest possible, therefore you cannot change it. Any change would make it 
larger, which is against the principles that govern Lisp evolution.

I hope that Nim finds a guiding principle that keeps it backward compatible 
with the work of the generations of programmers that will keep science moving. 


Re: Make Nim easier for the developer

2019-10-27 Thread shashlick
Check out nimterop which aims to do what you mention in #1. Nim certainly is 
very effective at binding to any shared or static library and nimterop makes it 
more seamless. As always there's a long way to perfection but it is already 
capable. 


Re: Make Nim easier for the developer

2019-10-27 Thread edu500ac
Hi, AMoura.

I don't care about language popularity, university ranking and the like, 
specially the kind of popularity that one measures with tools, such as TIOBE 
index and Webometrics. Let me tell you why. Let us consider university ranking. 
There is a very low ranked university in Russia, which is Bauman State 
Technical University. In The Times Higher Education - World University Ranking, 
the Bauman University is bundled in the 801-1000 bracket, together with 
University of Lagos, São Paulo State University, Rochester Institute of 
Technology, Catholic University of Peru, and 200 other low impact institutions. 
You will probably conclude that alumni of such a low ranked school don't even 
know the periodic table... Well, they not only know the periodic table, but 
they invented it. The periodic table was discovered by Dmitri Mendeleev, who 
happened to be a professor at Bauman. You are receiving my answer thanks to the 
miracle of satellite-relayed long distance communications, which was invented 
by people from Bauman University. By the way, Sergei Korolev from Bauman 
created the first satellite, and the second, and the third probe to reach the 
moon, and the second, and the first probe to reach Venus, and the second, and 
all nine probes that reached Venus. The first man in orbit was another feat of 
Sergei Korolev, the father of astronautics. Sergei Korolev and Dmitri Mendeleev 
were not exceptions, sinc Bauman University has other bright alumni: Pavel 
Sukhoi (airplane designer), Andrey Tupolev (first supersonic commercial jet), 
Vladmir Chelomei (aerospace engineer), Nikolay Dollezhal (first nuclear reactor 
for producing electricity), Sergei Lebedev (created the first practical 
computer, which as used to launch Sputnik 1, the first artificial satellite), 
Alexander Kermudzhian (interplanetary rovers), Zou Jiahua (industrialization of 
China), etc. Anyway, we are here for discussing Nim. Then, let us discuss Nim. 
Here is how to call a C procedure from Nim:

1 -- Write the C procedure, and save it in, say, addints.c


// File: addints.c
int addTwoIntegers(int a, int b) {
  return a + b; }


Run

2 -- Compile the C procedure into a library:


› gcc -c addints.c
› ls *.o
addints.o
› ar rvs addlib.a addints.o
› ls *.a
addlib.a


Run

2 -- Write a Nim program:


# File: addthem.nim
import os, strutils
{.compile: "addints.c".}
proc addTwoIntegers(a, b: cint): cint {.importc.}

when isMainModule:
  echo addTwoIntegers(paramStr(1).parseInt.cint, 7)


Run

3 -- Compile it and run:


› nim c --passL:addlib.a --nimcache:xx -d:release -o:sum.x addthem.nim
Hint: used config file '/etc/nim/nim.cfg' [Conf]
Hint: system [Processing]
Hint: widestrs [Processing]
Hint: io [Processing]
Hint: addthem [Processing]
CC: addints
CC: stdlib_io.nim
CC: stdlib_system.nim
CC: addthem.nim
Hint:  [Link]
Hint: [SuccessX]
› ./sum.x 35
42


Run

It seems that Nim poses no problem for linking an application to C. Let us see 
the other way around. Let us link Nim to Lisp, which happens to be my favorite 
Language. I am using a Macintosh, therefore, I will link Nim programs to a 
.dylib dynamic library. The Lisp I will choose is Chez Scheme, one of the 
nicest compilers in existence:

1 -- Let us start with a Makefile, since the command line is somewhat long:


# Makefile
all:
 nim c -d:danger --noMain --header\
  --deadCodeElim:on --app:lib\
  --opt:size --nimcache:./lixo\
  -o:Fibonacci.dylib --gc:none fib.nim


Run

2 -- Here is the nim program:


# This module provides a simple "Fibonacci"
# function to test Nim FFI.

# An asterisk * exports an identifier and
# makes it available for use by modules or
# other languages. E.g. FibNum* makes
# FibNum available with the "nfib" name.

proc FibNum*(n: int): int {.exportc: "nfib"} =
  if n < 2: 1
  elif n < 3: n
  else:
FibNum(n - 3) +
FibNum(n - 2) +
FibNum(n - 2)


Run

3 -- Finally, let us run the Nim programa from another language:


~/nim/libs$ scheme
Chez Scheme Version 9.5.3
Copyright 1984-2019 Cisco Systems, Inc.

> (load-shared-object "Fibonacci.dylib")
> (define fb (foreign-procedure "nfib" (int) int))
> (fb 5)
8
> (time (fb 42))
(time (fb 42))
no collections
0.001091174s elapsed cpu time
0.001445000s elapsed real time
0 bytes allocated
433494437


Run