TinyCC/tcc vs zig cc compile-times/etc.

2021-12-05 Thread Hlaaftana
I don't think you need to justify disagreeing with triggerhappy removals very 
much. tcc is mentioned countless times talking about Nim. The way to get rid of 
the burden of supporting it isn't to delete it but manage expectations, which 
is already done by keeping issues about it open.


What is programming?

2021-12-05 Thread carterza
While I refuse to engage in anything approaching productive discourse in 
relationship to this community anymore, I had to reply as this made me lol.

To be fair though, @jorjun_arch has yet to invent an entire cast of PhDs / 
doctorates yet to elaborate on their points. Yet

Seriously though, this thread is way more "on the rails" than that one schizo 
thread was... Wish I could find iti.


Using if/case expressions as real expressions?

2021-12-05 Thread ynfle
Basically, something is needed to "bind" the statement to the previous 
expression to tell the compiler it's an expression not a statement. So 
technically the following 2 things works 


var x: int

`+=`(x):
  if true:
1
  else:
0


Run


echo do:
  if true:
1
  else:
0


Run


Using if/case expressions as real expressions?

2021-12-05 Thread ynfle
I'm pretty sure it's because `+=` is a regular infix operator just like `div` 
or `mod` but `=` isn't. ie. the following doesn't work 


echo
  if x == 2:
2
  else:
-1


Run


Using if/case expressions as real expressions?

2021-12-05 Thread Pyautogui

import strutils

var vertical_direction = 0
var horizontal_direction = 0

for line in "input.txt".readFile.splitlines:
  let
line_parts = line.split " "
direction = line_parts[0]
magnitude = parseInt line_parts[1]
  
  var sas: int = case direction # works
  of "up": -magnitude
  of "down": magnitude
  else: 0
  
  vertical_direction += (case direction: # Works, probably due to 
parenthesis
  of "up": -magnitude
  of "down": magnitude
  else: 0)



Run

I guess it is due to conflicting operator precedence rules, with `+=`. IDK 
really though, new to Nim. (Glad to see you are a member of my Nim programming 
language Quora space!) 


Using if/case expressions as real expressions?

2021-12-05 Thread gavr
Hello, my first post is here. I saw this tweet and decided to rewrite it to nim 



import strutils

var vertical_direction = 0
var horizontal_direction = 0

for line in "input.txt".readFile.splitlines:
  let
line_parts = line.split " "
direction = line_parts[0]
magnitude = parseInt line_parts[1]
  
  var sas: int = case direction # works
  of "up": -magnitude
  of "down": magnitude
  else: 0
  
  vertical_direction += case direction # ERROR expression expected
  of "up": -magnitude
  of "down": magnitude
  else: 0




Run

But I ran into a strangeness, the error `expression expected`, although 
according to the 
[manual](https://nim-lang.org/docs/manual.html#statements-and-expressions-if-expression)
 if and case are expressions.

So, is they are simply intended to be used with a variable declaration only?


Understanding error with generic anonymous vs auto

2021-12-05 Thread ElegantBeef
An anonymous generic proc doesnt make much sense as an instance has to be 
instantiated so a specific type needs to be specialized. Whereas `auto` says to 
the type match "Hey if these match param count swap in the types", so it's 
sorta expected that anonymous generic doesnt compile since it's a pointless 
operation.


Understanding error with generic anonymous vs auto

2021-12-05 Thread geekrelief
In this example : 


import sequtils
let foo = @["It", "was", "a", "bright", "cold", "day", "in", "April."]

echo foo.map(proc(y:auto): auto = len(y))

echo foo.map(proc[T](y:T): auto = len(y))


Run

This is a minimal toy example born out of a discord discussion. The second 
`echo` generates: `(6, 19) Error: expected: ')', but got: '['`

Is this a compiler bug? It seems like the procs should be equivalent.


What is programming?

2021-12-05 Thread Pyautogui
Thank you. Good to know.


Advent of Nim 2021

2021-12-05 Thread lscrd
My repository is here: 


Advent of Nim 2021

2021-12-05 Thread Zoom
I like how simple your parsing for the boards in day 4 is. I spent too much 
time writing a "buffered/chunk" iterator extension for zero_functional and 
failed! :D

Here's my repo: 

I'm not sure I'll be able to keep the tempo, but we'll see.

For those using Matrix, the bridged room is 
[#nim-aoc:matrix.org](https://matrix.to/#/#nim-aoc:matrix.org)


async with delegates, how to pass parameters?

2021-12-05 Thread arnetheduck
What we do in [chronos](https://github.com/status-im/nim-chronos) is the 
following:


proc downloadPage(url: string) {.async.} = echo url

let f: proc(url: string): Future[void] = downloadPage

waitFor f()


Run

I presume the same thing works with asyncdispatch.


Nim v1.2.14 released

2021-12-05 Thread arnetheduck
Actually, for anyone looking for ideas on upgrade paths between Nim versions, 
here's a writeup of what we're doing: 


In particular, it involves testing with multiple nim releases, and recognizing 
that when developing libraries, a library is more useful the more versions of 
its dependencies that it supports (and tests) - this means that the more 
generally useful the library, the better it is if it supports older Nim 
versions - conversely, when developing applications, you want to support only 
one version of everything and have control over what you upgrade, at when. 


What is programming?

2021-12-05 Thread PMunch
There isn't anything wrong with discussing non-Nim things here, as long as it 
is slightly related and doesn't get super disruptive. If you don't want to 
engage in a certain discussion simply don't open the topic.


async with delegates, how to pass parameters?

2021-12-05 Thread kobi
Hi everyone!

I am trying to figure out how to do async, with delegates.

I want to use `withTimeout` from `asyncdispatch` module, and for that I need a 
future.

Now I have a proc that takes an argument, for example, 


proc downloadPage(url:string){.async.} = echo url


Run

and I want this to be a delegate, that is, I can choose different procs for 
this. `let f : Future[void] = downloadPage(url)` But in this case, it would run 
immediately. I couldn't find a simple way to create a `newFuture(procToRun, 
arguments)`

For this to become a delegate and not run immediately, I wrapped it in a 
`proc(){.async.} = downloadPage(url)`

But then I cannot use withTimeout on it, since it's no longer a Future[void]

What am I missing? how to do this?


async with delegates, how to pass parameters?

2021-12-05 Thread kobi
some sample code: 


import asyncdispatch

proc downloadPage(url:string){.async.} = echo url
let url = "someUrl"
let f:Future[void] = proc(){.async.} = waitFor downloadPage(url)


Run