Advent of Nim 2021

2021-12-02 Thread ynfle
Include is REALY COOL!


Dynamic usage of arithmetic operators in nim

2021-12-02 Thread Hlaaftana
The problem isn't that it's overloaded. `+` is a "magic" proc, it generates 
different inline code per backend, so it's not a real function. Overloads, 
including generic overloads, work:


import sequtils

proc foo[T](x: T): int = x + 1
proc foo[T: bool](x: T): int = -1

echo @[1, 2, 3].map(foo)


Run


Advent of Nim 2021

2021-12-02 Thread bg
Hi all! Sharing my repo too: 


TLS protocol negociation (TLS-ALPN)

2021-12-02 Thread shirleyquirk
worth having a look at  so you don't 
duplicate work you don't need to.


Dynamic usage of arithmetic operators in nim

2021-12-02 Thread xigoi
I think it would be interesting to have a convenient way to get a specific 
overload of a procedure. It feels weird to write things like 
`arr.mapIt(frobnicate(it))`.


Dynamic usage of arithmetic operators in nim

2021-12-02 Thread cobbycobby
Hi guys

I am looking for a way to write code in nim that behaves similar to this Python 
piece


In [1]: import operator

In [2]: d = {'*': operator.mul, '+': operator.add}

In [3]: op = '+'

In [4]: d[op](2, 3)
Out[4]: 5

The problem is that I do not understand how I can store reference to an 
operator in a Table


Dynamic usage of arithmetic operators in nim

2021-12-02 Thread DavideGalilei
Here's an example on how you can do this using a table of procs: 



Dynamic usage of arithmetic operators in nim

2021-12-02 Thread treeform
Nim does not have "operator" module but you can quickly create your own little 
closure functions that use the operator. Looks nearly identical to python then:


import tables

let d = {
  '*': proc(a, b: int): int = a * b,
  '+': proc(a, b: int): int = a + b
}.toTable()

let op = '+'

echo d[op](2, 3)


Run


Advent of Nim 2021

2021-12-02 Thread pietroppeter
published the blogpost for day 2 (which tells the story of the magic `include` 
trick for parsing 🤯): 


I remembered also that we should add our nim repos to the usual [awesome advent 
of code repo](https://github.com/Bogdanp/awesome-advent-of-code)


Nimview - a lightweight UI helper

2021-12-02 Thread marcomq
Will try :) I'm not good in youtube or writing blogs. But its high prio on my 
current schedule. Will have some vacation soon. Maybe I find some time for it.


Order of execution: where to find understanding

2021-12-02 Thread argl
Sorry if that offended you, that was not my intention. Just me trying to make 
sense of your question.


TLS protocol negociation (TLS-ALPN)

2021-12-02 Thread icedquinn
I cleaned up the BearSSL headers to run through a binding generator. My 
generator doesn't yet output actual Nim code though. Something that needs to be 
done (but then will have support for the gnome stack and enlightenment guis 
since those are ready for it too.)


Order of execution: where to find understanding

2021-12-02 Thread freeflow
@PMunch. Apologies, I was trying to attach my reply to the comment by @Argl but 
messed up so instead they got added as general comments. Whilst I could edit to 
remove the text, I wasn't allowed to delete the (now empty) comments.

Thanks for the explanation. The analagous situatione in VBA would be code the 
Class_Initialize method. Such code is run the first time an instance of the 
class is encountered on the RHS of an expression.


Order of execution: where to find understanding

2021-12-02 Thread PMunch
@freeflow, please don't spam your own topic with multiple comments. And the 
snarkier you are the less likely people are to help you.

The order of execution of a Nim program is simply so straight forward that I'm 
not sure we have any reference material/documentation for it. The closest thing 
would probably be our beginner guides.

One way to think about it is that everything you put in the global scope (ie. 
not inside any procedure) will be concatenated together into a `main` 
procedure. So in your case you might see your program (fully combined) as:


import strutils
import strformat
import sequtils
import Constants

const InputData = "Day01.txt"

type
  State = object
Integers: seq[int]

proc Part01() =
  var myResult:int=0
  for myIndex in 1..

proc Part02() =
  var myResult:int=0
  var mySum:seq[int]
  
  for myindex in 2..

proc Execute*()=
  Part01()
  Part02()

proc Main() =
  let s = State(Integers: toSeq((RawDataPath & 
InputData).lines).map(parseInt))
  Day01.Execute()

Main()


Run

This of course isn't valid Nim code since the variable `s` now exists only in 
the `Main` procedure scope. But if you think about it in an object/method sense 
then `s` would be a member of an invisible `Program` class, the `Main` 
procedure would be run for this class, populate the `s` variable, and then call 
the rest of your procedures.


Order of execution: where to find understanding

2021-12-02 Thread freeflow
Kind, thoughtful, considerate - not


Order of execution: where to find understanding

2021-12-02 Thread freeflow
Kind, thoughtful, considerate - not!!


Order of execution: where to find understanding

2021-12-02 Thread freeflow
@jyapayne Mainly VBA and a little bit of C#. I'm not a professional programmer. 
I'm not used to code that is not enclosed in a Method (procedure definition) 
inside a names module or class . In VBA the let statement above would be 
illegal. I wanted to read up on it to be aware of what I can and can't do with 
such 'unwrapped code'

I'm still waiting for a pointer to a document/reference.


Order of execution: where to find understanding

2021-12-02 Thread freeflow
Kind, thoughtful, considerate - not!!!


Order of execution: where to find understanding

2021-12-02 Thread argl
I get the impression you don't see the difference in the example code between 
_defining a procedure_ and _calling a procedure_. If that is the case 
[https://nim-lang.org/docs/tut1.html#procedures](https://forum.nim-lang.org/postActivity.xml#httpscolonslashslashnimminuslangdotorgslashdocsslashtut1dothtml-procedures)
 might help. Not sure if that part of the manual is best suited though, just my 
best/quick guess.


Order of execution: where to find understanding

2021-12-02 Thread jyapayne
@freeflow what programming language background do you come from?


Advent of Nim 2021

2021-12-02 Thread PMunch
Here is my repository: . I also hope to 
stream as many of my solutions as possible, link in the repository.


Order of execution: where to find understanding

2021-12-02 Thread xigoi
The statements execute in the order that they're written. It's not rocket 
science.


Order of execution: where to find understanding

2021-12-02 Thread PMunch
Nim files are executed top to bottom. When you import "Day01" it encounters the 
let statement and since it's a global it computes it. Then you call the 
`Execute` procedure that calls all the procedures.


Order of execution: where to find understanding

2021-12-02 Thread freeflow
Can someone point me to which document describes the order of execution of code 
in files. In particulate why the let statement in the code below executes 
before any of the procs.

In file Day01.nim 


import strutils
import strformat
import sequtils
import Constants

const InputData = "Day01.txt"


type
  State = object
Integers: seq[int]

let s =State( Integers:toSeq((RawDataPath & InputData).lines).map(parseInt) 
)

proc Part01() =

var myResult:int=0
for myIndex in 1..

proc Part02() =

var myResult:int=0
var mySum:seq[int]

for myindex in 2..

proc Execute*()=
Part01()
Part02()


Run

In file Main



import Day01

Day01.Execute()


Run


Nim at FOSDEM 2022 - CfP is open!

2021-12-02 Thread pietroppeter
glad to be of service, looking forward to seeing talk proposals from the the 
fine Nim crowd!


Advent of Nim 2021

2021-12-02 Thread erde74
Hi,

my repo 

i am a Nim beginner don't expect idiomatic Nim code ;)


This Month with Nim: November

2021-12-02 Thread geotre
Do you ask because Nimble doesn't work on your machine or because you don't 
like using it?


Preview of coming attractions?

2021-12-02 Thread PMunch
This topic seems to have strayed a bit off-topic for what it was originally 
intended as. There is certainly discussions to be had about fusion, but those 
would probably be better suited for a separate thread.


Preview of coming attractions?

2021-12-02 Thread Araq
We released a new version of Fusion. The next time problems arise, please use 
Fusion's issue tracker. If you get no feedback there, create an issue on Nim's 
issue tracker instead.


Advent of Nim 2021

2021-12-02 Thread remix
Yet another repo: