tests in the same files as the code

2020-07-15 Thread spip
>From Nim documentation: [Writing 
>tests](https://github.com/nim-lang/Nim/blob/devel/doc/contributing.rst#writing-tests)


Understanding Nim compiler

2020-07-16 Thread spip
Niklaus Wirth's books on compiler design and structured programming are very 
didactic. Wirth is a great author to explain how things work. And I just 
discovered that one of the books I read and used a long time ago is now 
available for free on the Web: [Compiler design in 
C](https://holub.com/compiler/) from Allen Holub. There was a curses GUI to go 
step by step and understand parsing. Would be nice if Nim compiler showed its 
internals in a similar way... ;-)


AsyncSocket seems to be dropping data

2020-07-16 Thread spip
Same assertion error on Linux.


...
RCVD #269:  000269 This is message #269 of ∞. Please stay tuned for more. 
000269 This is me...
RCVD #270:  000270 This is message #270 of ∞. Please stay tuned for more. 
000270 This is me...
RCVD #715:  000715 This is message #715 of ∞. Please stay tuned for more. 
000715 This is me...
 ERROR: Server received #715, but last was #270!
toto.nim(63) toto
.choosenim/toolchains/nim-#devel/lib/pure/asyncdispatch.nim(1932) waitFor
.choosenim/toolchains/nim-#devel/lib/pure/asyncdispatch.nim(1614) poll
.choosenim/toolchains/nim-#devel/lib/pure/asyncdispatch.nim(1360) runOnce
.choosenim/toolchains/nim-#devel/lib/pure/asyncdispatch.nim(208) 
processPendingCallbacks
.choosenim/toolchains/nim-#devel/lib/pure/asyncmacro.nim(23) 
runServerNimAsyncContinue
toto.nim(25) runServerIter
.choosenim/toolchains/nim-#devel/lib/system/assertions.nim(29) 
failedAssertImpl
.choosenim/toolchains/nim-#devel/lib/system/assertions.nim(22) raiseAssert
.choosenim/toolchains/nim-#devel/lib/system/fatal.nim(49) sysFatal
[[reraised from:
toto.nim(63) toto
.choosenim/toolchains/nim-#devel/lib/pure/asyncdispatch.nim(1932) waitFor
.choosenim/toolchains/nim-#devel/lib/pure/asyncdispatch.nim(1614) poll
.choosenim/toolchains/nim-#devel/lib/pure/asyncdispatch.nim(1360) runOnce
.choosenim/toolchains/nim-#devel/lib/pure/asyncdispatch.nim(208) 
processPendingCallbacks
.choosenim/toolchains/nim-#devel/lib/pure/asyncfutures.nim(431) 
asyncCheckCallback
]]
Error: unhandled exception: toto.nim(25, 16) `n == lastN + 1`
Async traceback:
  toto.nim(63)  toto
  .choosenim/toolchains/nim-#devel/lib/pure/asyncdispatch.nim(1932) waitFor
  .choosenim/toolchains/nim-#devel/lib/pure/asyncdispatch.nim(1614) poll
  .choosenim/toolchains/nim-#devel/lib/pure/asyncdispatch.nim(1360) runOnce
  .choosenim/toolchains/nim-#devel/lib/pure/asyncdispatch.nim(208)  
processPendingCallbacks
  .choosenim/toolchains/nim-#devel/lib/pure/asyncmacro.nim(23)  
runServerNimAsyncContinue
  toto.nim(25)  
runServerIter
  .choosenim/toolchains/nim-#devel/lib/system/assertions.nim(29)
failedAssertImpl
  .choosenim/toolchains/nim-#devel/lib/system/assertions.nim(22)
raiseAssert
  .choosenim/toolchains/nim-#devel/lib/system/fatal.nim(49) sysFatal
Exception message: toto.nim(25, 16) `n == lastN + 1`
Exception type: [AssertionDefect]
Error: execution of an external program failed: 'toto '


Run


Choosing between generic and specific fn

2020-07-19 Thread spip
Though they look like functions, templates are strange beasts...

It seems that your template looks at the symbols it knows when it is 
instantiated, and it will select the most specific in the known symbols at that 
time. If both procs have been parsed by the compiler when invoked, it will 
choose the specific one.


proc x[T](i: T) =
  echo "generic x"

proc x(i: int) =
  echo "specific x"

template temp(a) =
  x(a)

temp(14)


Run

But if when the template is instantiated and only the generic proc symbol is 
known at that time, the compiler will not try to find if another overloaded 
proc exist. And in your example it will select the generic proc.

I would have to look at Nim sources to confirm that behaviour.

I've tried to [list such template 
behaviours](https://github.com/nim-lang/Nim/wiki/Templates) in order to 
complete Nim template documentation.


How to ensure that all attributes of an object are explicitly set during creation?

2020-07-29 Thread spip
Why is this pragma not the default behaviour? It seems to me that's a better 
practice to ensure that all fields are initialized by the programmer than 
relying on the compiler initializing them with a default value. Or at least 
there could be a compiler define to ensure this default behaviour.


Why use range[0..255] instead of char?

2020-08-11 Thread spip
Not in a strongly typed language. A `char` is a character while a `range[0 .. 
255]` is an integer in the range 0 to 255.

Just like the temperature of my oven can not be interpreted as an amount in my 
wallet!;-)


How to operate on tabular data in Nim?

2020-08-20 Thread spip
Have a look at the Data Science section in the [curated 
packages](https://github.com/nim-lang/Nim/wiki/Curated-Packages).


Nim's alternative for returning default values using short-circuit-evaluation

2020-09-03 Thread spip
`if` are 
[expressions](https://nim-lang.org/docs/manual.html#statements-and-expressions-if-expression)
 and you could rewrite `getTitle` like 


proc getTitle(m: MyType): string =
  result = if m.title != "": m.title
  elif m.foo != "": m.foo
  elif m.bar != "": m.bar
  else: m.buzz


Run


stdlib pattern matching feedback

2020-09-23 Thread spip
Have you had a look at the syntax proposed by the different [pattern matching 
modules](https://github.com/nim-lang/Nim/wiki/Curated-Packages#language)?


weird nim parser problem

2020-09-29 Thread spip
[Similar parsing features](https://forum.nim-lang.org/t/6189). Using correct 
spacing is important in Nim, for the parser and for those who read your code.


Is experimental "parallel" compatible with "--gc:arc"?

2020-10-25 Thread spip
I'm playing with a parallel CSV parser and I'm getting `SIGSEGV: Illegal 
storage access. (Attempt to read from nil?)` during the reduce operation from 
the parallel parsers, with the stack trace pointing at the GC code: 


.../Development/fastparse/src/fastparsepkg/fparsecsv.nim(281) read_csv_para 
 ==> result.headers = csv.headers
.../.choosenim/toolchains/nim-1.4.0/lib/system/assign.nim(175) 
genericSeqAssign
.../.choosenim/toolchains/nim-1.4.0/lib/system/assign.nim(139) genericAssign
.../.choosenim/toolchains/nim-1.4.0/lib/system/assign.nim(97) 
genericAssignAux
.../.choosenim/toolchains/nim-1.4.0/lib/system/gc.nim(447) newSeq
.../.choosenim/toolchains/nim-1.4.0/lib/system/gc.nim(439) newObj
SIGSEGV: Illegal storage access. (Attempt to read from nil?)


Run

Running with valgrind detects _many_ `Conditional jump or move depends on 
uninitialised value(s)` or `Use of uninitialised value of size 8` errors in GC 
code too, but at least it completes execution and print the results.

So I decided to use `--gc:arc` but now the compiler SIGSEGVs while compiling 
the code! Using `--gc:none` makes compilation fails on 
`.../.choosenim/toolchains/nim-1.4.0/lib/system/mmdisp.nim(96, 77) Error: 
undeclared identifier: 'newObj'`. Only `--gc:boehm` gives the expected results 
though valgring still complains...

There are good odds that's the bug is in my code and I understand that Nim 
experimental features could have dark corners, but what are the methods to 
detect if the bug is on my side of the code or on Nim compiler side?


signal processing in Nim?

2020-10-28 Thread spip
Look at [science 
packages](https://github.com/nim-lang/Nim/wiki/Curated-Packages#science)


Capturing a context variable in public procs

2020-11-09 Thread spip
I'm working with an external library that requires passing a context variable 
to all library calls. As I'm writing a DSL to ease using this library, I'd 
rather hide this context variable to the user of the DSL. Is there a way to 
achieve like a closure capture variable for public procs?

For instance, the following DSL code 


math:
  a = (b + c) * d


Run

would be translated to something like: 


template math*(body: untyped) =
  block:
let ctx {. inject .} = initLib()
`body`

proc `+`*(a, b: Mat): Mat =
  result = libAdd(ctx, a, b)

proc `*`*(a, b: Mat): Mat =
  result = libMult(ctx, a, b)


Run

where the `ctx` variable is captured in procs `+` and `*`, resulting in


block:
let ctx {. inject .} = initLib()
a =  libMult(ctx, libAdd(ctx, b, c), d)


Run

if the two procs were templates.

I've been using templates to achieve the result but 1) templates are bugged 
when dealing with "generics" syntax 2) templates can give unexpected results 
when arguments with side effects are evaluated multiple times, 3) though 
templates are evaluated a compile time, syntax errors in the code will stay 
hidden until the template is used, 4) the type of the template is known only 
when it is evaluated, 5) debugging templates is more difficult than standard 
code, etc. See the [wiki](https://github.com/nim-lang/Nim/wiki/Templates) for 
risks of using templates...

Ideally, because the DSL code can be used in multiple procs or even in 
recursive code, I need to capture the latest `ctx` in the `math` scope. If I 
can declare inner _closure_ procs as public, it would do the job... but it 
can't be done.

Is it possible to do what I want to do?


How to prevent a program from crashing when the "OSError: Too many open files" error occurs?

2020-11-10 Thread spip
Or you can define a file _autocloser_ like shown in 
 when you 
don't need to keep the files opened.


Capturing a context variable in public procs

2020-11-10 Thread spip
>From what I understand, I will have to go with the macro route and manage the 
>full DSL language syntax. I have to think about it before jumping as my DSL 
>can be mixed with Nim code and only the calls to the library needs to get the 
>context variable (I used a math syntax in my example but the language is more 
>general).

Like H. L. Mencken said, _For every complex problem there is an answer that is 
clear, simple, and wrong._. And using templates to define a large DSL is such a 
solution...

Thanks for the hints and experience feedback.


publishing a nimble package

2020-11-10 Thread spip
I'm not sure the `nimble publish` method works. Here is the hard way: clone the 
[nimble packages](https://github.com/nim-lang/packages) repository and update 
the `packages.json` file with your new package metadata. Them ask for a pull 
request.

The whole process is more documented in the 
[README](https://github.com/nim-lang/packages).


Capturing a context variable in public procs

2020-11-11 Thread spip
For the record, another simple but wrong solution:

> It's possible to not use templates if you define your DSL in the math body:


template math*(body: untyped) =
  block:
proc `+`*(a, b: Mat): Mat =
  result = libAdd(ctx, a, b)

proc `*`*(a, b: Mat): Mat =
  result = libMult(ctx, a, b)

let ctx {. inject .} = initLib()
`body`


Run

results in [Error: 'export' is only allowed at top 
level](https://play.nim-lang.org/#ix=2DQQ)


Capturing a context variable in public procs

2020-11-11 Thread spip
Inspired by the `with` 
[macro](https://nim-lang.org/docs/with.html#with.m%2Ctyped%2Cvarargs%5Buntyped%5D),
 I'm thinking of writing a macro to inject the `ctx` into all `libXXX` calls 
while walking the AST. But in order for the procs to compile, I would have to 
write them like:


# Fake libXXX API to allow compilation
proc lib2Mult(a, b: Mat): Mat = discard
proc lib2Add(a, b: Mat): Mat = discard

# Real libXXX API
{. pragma: libXXX, importc, dynlib: libName, cdecl .}
proc libMult(ctx: Ctx; a, b: Mat): Mat {. libXXX .}
proc libAdd(ctx: Ctx; a, b: Mat): Mat {. libXXX .}

proc `*`(a, b: Mat): Mat =
  result = lib2Mult(a, b)

proc `+`*(a, b: Mat): Mat =
  result = lib2Add(a, b)


Run

The macro would replace the fake `lib2XXX` calls by `libXXX` and inject the 
`ctx` variable.

Some thoughts before starting to code:

  1. Adding fake declarations is not really nice. I can try to hide them with a 
template when I declare the API procs.
  2. Identifying the fake calls must be done with a pattern (`lib2.*`) and this 
should help identify the real call (`libXXX`).
  3. Accessing the `ctx` value from outside proc bodies will probably require 
pointer handling, in the unsafe area...




Capturing a context variable in public procs

2020-11-12 Thread spip
Yes, that's [true](https://play.nim-lang.org/#ix=2DXj). Probably simpler than 
writing the decorating macro, but the documentation comments from the inner 
procs won't be taken into account by `nim doc`? I'm still thinking about the 
easiest syntax for users...


Capturing a context variable in public procs

2020-11-13 Thread spip
I've simplified my problem to present it in the forum. Presently, I'm not using 
a template but a macro because configuration options must be processed before 
creating the context variable. And I've a few hundreds user functions, split in 
multiple files that I have to include. Documenting them all in the `math` doc 
comment is not that simple!:-(


Life is nice...

2020-11-14 Thread spip
... when you see that the Nim compiler is smart enough to [differentiate 
between an array access and a generic call](https://play.nim-lang.org/#ix=2EbI) 
while the programmer has difficulties with the syntax...


var bar: array[1 .. 1, proc (y: int): int]

proc fuzz(x: int): int =
  x * x

bar[1] = fuzz

proc foo[x: static int](y: int): int =
  y

echo "foo[1](2) = ", foo[1](2)
echo "bar[1](2) = ", bar[1](2)


Run

This prints 


foo[1](2) = 2
bar[1](2) = 4


Run


Which HTTP server library?

2020-11-15 Thread spip
You could start looking 
[there](https://github.com/nim-lang/Nim/wiki/Curated-Packages#web) and then 
extend your search to Nimble packages...


Real sets and tables anywhere?

2020-11-16 Thread spip
Well, there is [Nim for Python 
programmers](https://github.com/nim-lang/Nim/wiki/Nim-for-Python-Programmers) 
and reading at least the [Tutorial](https://nim-lang.org/learn.html) will 
answer your questions...


Open-ended slices

2020-11-16 Thread spip
Like in from alpha to omega? `alpha .. X` is bottom-opened range while `Y .. 
omega` is top-opened range!;-)


Gedit syntax highlighting.

2020-11-16 Thread spip
@Stefan_Salewski, your 
[nim.lang](https://raw.githubusercontent.com/StefanSalewski/NEd/master/nim.lang)
 and 
[nimdark1.xml](https://raw.githubusercontent.com/StefanSalewski/NEd/master/nimdark1.xml)
 are well supported in recent Ubuntu.


# as root
cp nimdark1.xml /usr/share/gtksourceview-4.0/styles/
cp nim.lang /usr/share/gtksourceview-4.0/language-specs/


Run

Having them included in Gedit source would enhance Nim exposure and promote the 
language...


are nim exceptions "zero cost" (on error-free execution) ? (if so, `defer` should be used more)

2020-11-16 Thread spip

when true:
  block:
template main1 =
  echo "ok1"
  defer: echo "ok3"
  echo "ok2"
main1()
main1()


Run

> [ok1 ok2 ok1 ok2 ok3 ok3](https://play.nim-lang.org/#ix=2Eqq)

But that's not what states the [Nim 
Manual](https://nim-lang.org/docs/manual.html#exception-handling-defer-statement)
 where it is written that `defer:` statements are rewritten to `try: ... 
finally:`. That's the reason why I never used `defer:` as I thought that the 
`try: ... finally:` scope rules were more clear.

With that semantic, `defer:` is **really different** from `try: ... finally:` 
and the manual paragraph should be changed.


are nim exceptions "zero cost" (on error-free execution) ? (if so, `defer` should be used more)

2020-11-17 Thread spip
@timothee, I know that this thread is talking about exception but perhaps the 
revised documentation should precise that `defer` works with exception scope. 
`defer` code won't run at closure iterator end of scope like in the following 
example.


import os

proc bar(name: string): iterator: string =
  iterator foo: string {.closure.} =
echo "Open file ", name
var file = open(name)
defer:
  echo "Close file ", name
  close(file)
var line: string
while readLine(file, line):
  yield line
  
  result = foo

echo "Program starts"
var iter = bar(paramStr(1))

var i = 0
for l in iter():
  inc(i)
  echo "Read line #", i, "=", l
  if i > 5:
break;

echo "Program completed"


Run

Run it with `nim c -r bug.nim bug.nim`. It would have been nice though for 
universal and simple resources cleaning...


Sample compiler/interpreter (like kaleidoscope/llvm, monkey/go etc)

2020-11-18 Thread spip
Have a look 
[here](https://github.com/nim-lang/Nim/wiki/Curated-Packages#language) and then 
you can extend your search to nimble packages...


Why is the implicit `result` so widely used?

2020-11-20 Thread spip
@juancarlospaco, what do you want to show? Is it that [result value is not set 
when return is used](https://play.nim-lang.org/#ix=2ENS)?


Strange error message from collections/sets.nim

2020-11-23 Thread spip
Well,ifyo ulik etodro pwhi tespac esatra ndom,Ni mwo n'tbeyo urfri end... Like 
in many languages!;-)


Nim Community Survey 2021

2022-01-14 Thread spip
I've frequently seen a split between North American and European developers 
based on language syntax preference. North Americans favour brace blocks `{ ... 
}` _à la C_ while European rather use Algol-originating `begin ... end` blocks 
or indented syntax like Python. Look at the origin of languages like Java, C#, 
Go, Rust, etc. compared with Python, Ada, Nim, Pascal, Pony, etc.


NimForum 2.2.0 - Fixes a big CVE!

2022-01-30 Thread spip
And it can't be read with old iPad now. I have to find a computer with a modern 
browser...


NimForum 2.2.0 - Fixes a big CVE!

2022-01-31 Thread spip
Yes, it worked with Safari on iPad 2. I found that I can access it with Chrome. 
It is probably related to a Javascript library as there are less and less sites 
that are accessible from this tablet model.


Can Nim be made more "purely functional""...

2022-02-17 Thread spip
> Build a new language that uses Nim as a back end, using the functional code 
> from a language such as Elm to emit Nim code that would be converted to c/C++ 
> by Nim.

As macros are part of Nim language definition, so is Nim AST definition. If it 
were possible to plug into Nim compiler to provide an AST created with a 
functional language, you could have best of both worlds. A functional syntax 
after writing a parser for a new FP language, and efficiency of Nim binary 
generation (and of course stdlib and environment).


Macros that compose (and work well with auto-completion tooling)

2020-12-05 Thread spip
Could you add a reference to @timotheeocur's proposal so that we can compare 
both?


Is there a way to monitor the total memory usage of a Nim app?

2020-12-10 Thread spip
Have you looked at [Nim Memory Profiler](https://nim-lang.org/docs/estp.html)?


Nim style guide based on Nimbus experience

2021-02-03 Thread spip
Adding the link to the [Nim style 
guide](https://github.com/status-im/nimbus-eth2/blob/style-guide/docs/the_style_book/src/SUMMARY.md)
 because I did not found it in the first post.

And dropping a few comments...

  * This is very good read as it is based on experience. A copy should be 
available on Nim web site, not far from [NEP1: Standard Library Style 
Guide](https://nim-lang.org/docs/nep1.html). It would certainly help new comers 
and could be enhanced/discussed by Nim community.
  * Make the rules more granular and give them a name or a number, like in 
legal documents. This will allow to refer to them without ambiguity in 
discussions.



For instance: 


1.1. Language features
1.1.1. `import` a minimal set of modules using explicit paths.
1.1.2. `export` all modules whose types appear in public symbols of the 
current module.
1.1.3. Prefer specific imports.
1.1.4. Avoid include.


Run

  * Give explanations why. Sometimes there are Pros/Cons sections. These are 
rules of experience and not laws; they can be adapted to the context if the 
user understand the background why they were stated.



For instance: Why _Annotate each module with a top-level_ `{.push raises: 
[Defect].}`?

  * Be didactic. Not all readers are Nim experts, and in fact if they read this 
document it's to learn and grow from others' experience.



In the previous example, not all readers will understand what this does...

  * Give examples but don't add new rules in the code.



For example, in the [Import, 
export](https://github.com/status-im/nimbus-eth2/blob/style-guide/docs/the_style_book/src/03_language.md#import-export)
 example, the reader can find: 


1.1.5. Prefix modules imported from Nim standard library with `std/`.
1.1.6. Use full path name when importing "external" modules.
1.1.7. Use relative path when importing "local" dependencies.


Run

  * Like in some other web sites (I did not found a better example 
, readers should be 
able to comment/argument about a rule.




Array Difference

2021-04-06 Thread spip
Is the real problem about discoverability in the documentation?

[Difference of two 
sets](https://nim-lang.org/docs/system.html#-,set%5BT%5D,set%5BT%5D) is already 
there, though not with `seq`.

Do we need to improve the documentation search engine ([CTRL]+[F])? Do we need 
better or more descriptive proc names? Should we search also in the description 
of the procs or by categories?


[ANN] Nim0, a playground to learn compiler internals

2021-04-26 Thread spip
If you want to understand how Nim compiler works, start by looking under the 
hood of the Nim0 compiler, a Nim-compatible toy language with a compiler and an 
emulator for a RISC CPU. This project is much smaller than the Nim compiler, 
everything being packed in 5 Nim files. But most important is that all this is 
explained in Niklaus Wirth's [Compiler 
Construction](https://www.projectoberon.org/) book that you'll find in the 
`misc` directory with cross-references in source code.

Nim0 is a very limited subset of Nim ( _every Nim0 source is valid Nim syntax 
with very limited changes_ ). Many features are missing, like functions or the 
`result` instruction. But it still can be used to write quite complex programs 
like a Sudoku solver (look at the examples directory).

  * Repository: 
  * Documentation: 



Under Linux, you can easily try it and run your first program in 5 commands:


nimble develop nim0   # Install nim0
cd nim0
nim build # Build nim0 compiler
./nim0 comp examples/Factorial# Compile the Factorial example
./nim0 run examples/Factorial # Run Factorial until overflow...


Run

How can you use Nim0?

  * To learn how a compiler works. Try adding new features or optimising code 
generation. And then jump hacking Nim compiler...
  * To learn how an emulator works and learn a RISC assembler. Change the RISC 
target for a real CPU...
  * As a support for a computer science course. So small that your students 
will grab it whole and easier to read than C. Let them discover Nim...
  * Whatever you want. I needed a small language to try some ideas. Try yours...




[ANN] Nim0, a playground to learn compiler internals

2021-04-27 Thread spip
I don't care moving Nim0 repository from GitLab to GitHub if it can help 
collaboration on that project. I can even share it with another maintainer if 
someone is interested. For the current time, I've created a clone at 
.

But I don't think that this project is worth adding an AST. Wirth created 
Oberon-0 as an illustration for teaching CS and compiler construction. He 
wanted to keep it as simple as possible, though touching some important parts 
of compiler design like records or arrays. Nim0 is a direct port of Oberon-0 
compiler with a few enhancements. I kept Wirth's coding style in some parts 
even if using Nim could make the code nicer or I thought that more modern 
coding would improve it. It's really a pedagogical toy to learn compilation 
while reading the book _Compiler Construction_ and trying to do some exercises 
at the end of chapters.

If I wanted to have a more powerful bare compiler with an intermediate 
representation, I would start from scratch. Nim0 was thought to be a 
single-pass in-memory compiler with RISC code interpretation (Wirth even 
provided an FPGA hardware to execute programs). Adding an AST would require 
changing the whole code generation module and make the whole program more 
complex for beginners. As it is, it limits the type of language experiments you 
can do with it. But the goal of Nim0 is not to replace Nim compiler but to make 
it easier to understand how it works.


Tabulation symbols not allowed

2021-05-10 Thread spip
A simple way to check if your view is worth it, you can try to implement mixing 
tabs and spaces in [toy compiler Nim0](https://pmetras.gitlab.io/nim0/). You 
only have to look at the 5 
[ossIndentXXX](https://gitlab.com/pmetras/nim0/-/blob/master/src/OSS.nim#L186) 
procedures that manage syntax indentation for the compiler. The algorithm there 
is probably simpler that the one used in Nim, but if you manage to write a 
source file that mixes tabulations and spaces for indentation that the compiler 
and your editor are happy with, it will base the discussion on real code.

At the present time, it was easier to select a simple rule (no tabs in Nim 
source) than lose time on vaporware discussions, even if some users think that 
a better solution exists.


How to make Nim more popular

2021-05-12 Thread spip
I find strange that there is no German page for [Nim in 
Wikipedia](https://en.wikipedia.org/wiki/Nim_\(programming_language\)).


Int/Floating Point Cast Result

2021-05-17 Thread spip
Have you read [the blog post on Trace of 
Radiance](https://nim-lang.org/blog/2020/06/30/ray-tracing-in-nim.html)?


Nim for Beginners #26 Reference Objects

2021-09-20 Thread spip
> The other point is, that you said that for references we do not need the var 
> keyword when passing data to procs -- we can modify the fields of object 
> passed as references always. Well, beginners may be confused: Is the most 
> significant advantage of references that we don't have to type that var 
> keyword in the procedure signature? So why not always us references as done 
> in Java and Python, so that we never would have to use a var parameter.

That's a good question that always bother me. The only justification I found 
for keeping `var` parameters is that you can't call the proc that defines them 
with `nil` or constant values. So you provide a stricter API contract than 
declaring them with `ref`.


Integration with C for statistics and data processing?

2021-09-22 Thread spip
Or have a look at 
[https://github.com/nim-lang/Nim/wiki/Curated-Packages#science](https://forum.nim-lang.org/postActivity.xml#httpscolonslashslashgithubdotcomslashnimminuslangslashnimslashwikislashcuratedminuspackages-science)


Any known means of sorting UTF8 strings?

2023-04-27 Thread spip
Sorting code points is locale-dependant. Sorting in French is different from 
sorting in Spanish or German. The Unicode group has detailed the collation 
algorithm that uses the Unicode property files. If you want a general solution, 
ICU (or its variants) is the fastest path.


Dear Araq, how do I create a programming language?

2024-04-18 Thread spip
Building upon Araq's answer about Nicklaus Wirth book, you can start playing 
with [Nim0](https://gitlab.com/pmetras/nim0) that implements a toy 
_Nim-compatible_ language in Nim, with references to Wirth's text. You can even 
practice adding some missing features...