Why not use AI to create momentum in Nim?

2024-06-03 Thread hamidrb80
can AI suggest prototype ideas for killing another 40K people too?


Nim in university context?

2024-05-09 Thread hamidrb80
> And as a bonus LLMs are pretty bad at Nim, so I guess cheating would be 
> harder.

LOL

I use Nim for my homeworks, my profs were impressed that such language exist. I 
had presentation about it but I couldn't convince them to use Nim for teaching. 
[they use C++ & Python for that purpose ]


Sum types, 2024 variant

2024-04-17 Thread hamidrb80
would'nt be hard to do something like this?


var n: NimNode = ...
assert n.kind in nnkLiterals


Run

sure new style variants has better syntax, but I don't feel good about it.


nimble.directory has been down for a few days now

2024-03-01 Thread hamidrb80
the nimble.directory is down quite often these days.

Maybe running the website with commands like `retry` could help to run 
automatically after crash.




leave parenthesis for procedures that take 0 parameters like Ruby

2024-02-23 Thread hamidrb80
> paramCount is ?

Implicit procedure call


leave parenthesis for procedures that take 0 parameters like Ruby

2024-02-23 Thread hamidrb80
Hey, today I did something evil in Nim.

I was so sad that I have to write those extr parenthesis for some 
procedures like 
[paramCount()](https://nim-lang.org/docs/cmdline.html#paramCount).

I wished something like 
[Ruby](https://stackoverflow.com/questions/340624/do-you-leave-parentheses-in-or-out-in-ruby)
 ...


import std/os

converter procToCall[T](prc: proc(): T {.nimcall.}): T =
prc()

echo paramCount ## now works!


Run

Enjoy!


ImPlot library

2023-09-26 Thread hamidrb80
Amazing! please publish it to Nimble


Improving Examples and Documentation

2023-09-23 Thread hamidrb80
I have worked with React & VueJs before, Honestly in those frameworks they 
either have their own template (e.g. .vue files) or they have introduced new 
syntax (e.g. .jsx or .tsx) but in Nim it was a lot more straight forward, just 
a macro called `buildHTML` and `VNode` type.

The only confusion I had at the beginning was 
.

It's true that Karax does not have very detailed documentation like React & 
VueJS, obviously you can't come from zero experience and expect to know 
everything. But when you have a sense that how does it work, you can read its 
code and that does not kill you


The secret of Nim

2023-09-23 Thread hamidrb80
I Think it's microscopic image inside of a Nim crown. to see the Nim crown you 
have to zoom out :-/


SomeFloat in std/complex

2023-08-16 Thread hamidrb80
It reminds me of "monkey patching" in Python

Man I really hated it back then


[Scala background] How does a macro in Scala differs from macro in Nim?

2023-08-15 Thread hamidrb80
beef has [micros](https://nimble.directory/pkg/micros)


[Scala background] How does a macro in Scala differs from macro in Nim?

2023-08-14 Thread hamidrb80
Hey! I hope you have a good time.

recently I've noticed that Scala has Macros with the ability to manipulate 
**AST** just like Nim.

but surprisingly they don't advertising it ( I can't see much 
tutorials/projects about it ) which is opposite in Nim.

If you have background in programming with Scala, could you please explain how 
does a macro in Scala and Nim **differ** AND why aren't they more **_popular_** 
in Scala?

thanks


newSeq() named inconsistently?

2023-08-03 Thread hamidrb80
It would be nice to introduce `initSeq` in Nim 2


Why is a Nim enthusiast/programmer called a "Nimmer"?

2023-06-30 Thread hamidrb80
It reminded me stupid python community made ups:

  * Pythonista
  * Pythoneer




signalfd leaks in addProcess()

2023-06-29 Thread hamidrb80
please make a pull request


On term rewriting macros

2023-06-29 Thread hamidrb80
the examples in the docs does no convenience me, why not use a template?

instead of


template optMul{`*`(a, 2)}(a: int): int = a+a


Run

just write:


template `*`(a: int, b: static[2]): int = a+a


Run


Why is a Nim enthusiast/programmer called a "Nimmer"?

2023-06-29 Thread hamidrb80
I prefer: Nim ⋈ Ninja ==> Nimja


a simple way for generating UUID key

2023-06-26 Thread hamidrb80
`oids` does not work with `js` backend


Good Languages Borrow, Great Languages Nim

2023-05-19 Thread hamidrb80
Man "Nim" means half (½) in Persian.

Even worse, "Go" means "sh!t" in Persian 


using db_odbc with ms sql server on windows 10

2023-05-17 Thread hamidrb80
In a fresh Windows 10 machine, installing SQL Server 2022 Developer edition, 
the ODBC driver `SQL Server Native Client 11.0` is no longer included, as 
Microsoft does not recommend using the driver for new application development. 
Source 
.
 Therefore on connect, we'll receive error `[Microsoft][ODBC Driver Manager] 
Data source name not found and no default driver specified`.


How do you write a test with mock?

2023-01-11 Thread hamidrb80
you can use [mockingbird](https://github.com/PhilippMDoerner/mockingbird) but 
[I suggest not to use this approach to test your 
app](https://dpc.pw/my-case-against-mocking-frameworks)


Advent of Nim 2022

2022-11-30 Thread hamidrb80
https://github.com/hamidb80/problem-solving/tree/main/advent-of-code/2022


Nim 2: What’s special about Task?

2022-10-26 Thread hamidrb80
I've looked at std/tasks page in the stdlib, and cannot understand why's first 
block does not work:


import std/tasks

type
Runnable = ref object
data: int

proc hello(a: Runnable) =
a.data += 2

block:
let x = Runnable(data: 12)
let b = toTask hello(x) # error > expression cannot be isolated: x
b.invoke()

block:
let c = toTask(hello(Runnable(data: 12)))
c.invoke()



Run

simply because in the first block I initialized `Runnable` outside of arguments 
list?


"else" after loop

2022-09-01 Thread hamidrb80
[Python's creator wishes this feature never 
existed](https://www.youtube.com/watch?v=6Im38sF-sjo)


iterrr: extensible iterator library

2022-08-17 Thread hamidrb80
**UPDATE: version 1.0.4**

with [custom adapter](https://github.com/hamidb80/iterrr#custom-adapter) and 
custom reducer, it's really an _extensible iterator library_!

  * [here's](https://github.com/hamidb80/iterrr#example-of-generated-code) an 
example of generated code.
  * example of defining [flatten 
adapter](https://github.com/hamidb80/iterrr/blob/main/src/iterrr/adapters.nim#L122-L125)
  * see more in 
[tests](https://github.com/hamidb80/iterrr/blob/main/tests/test.nim)




Nim v2: what would you change?

2022-05-15 Thread hamidrb80
I wish Nim v2 have better Generic compatibility.


[news] NimScript won't report incorrect errors in vscode with the latest devel branch

2022-03-24 Thread hamidrb80
thank u for your awesome work!


iterrr: extensible iterator library

2022-03-21 Thread hamidrb80
> I agree that most cases are covered with those two, and some adapters can be 
> boiled down to just a filter and a map, but not always. Some actions which 
> require changes to the number of iterations can't be expressed with them, 
> some require internal state, some act on multiple iterables. For example:

why not use `itertools`? 


iterrr: extensible iterator library

2022-03-21 Thread hamidrb80
> Looks good to me!

**see new version `0.2.1`** with removed `i` prefix and infix style custom 
idents `=>`, you can write:


(1..10) |> map(n => _ )
(1..10) |> map((a1, a2, ...) => _ )


Run


iterrr: extensible iterator library

2022-03-21 Thread hamidrb80
> reusing [] for declaring idents looks poorly readable. Overloading the 
> meaning of a basic language construct is adding to the mental overhead. I 
> don't mind the slightly longer pseudo-closure syntax, as it's unambiguous and 
> non-intrusive.

I'm kinda agree with you, let me know if you think this is intuitive,


points |> imap((x,y) => x+y) ...


Run


Read output only while input is not asked

2022-03-21 Thread hamidrb80
I guess you should use Stream thingy in `a.nim`. take a look at: 



iterrr: extensible iterator library

2022-03-18 Thread hamidrb80
Thanks for your suggestion.

I think something like `iterrr` or `toIterrr` is good. Any other suggestions 
would be appreciated.

I plan to add `ifor` for nested loops. Something like `for*` in Racket-lang.


iterrr: extensible iterator library

2022-03-10 Thread hamidrb80
Hey. I've been working on a iterator library for 2 weeks.

I'm happy to announce you that made it to the stable point.

for quick introduction, you may used `std/sequtils`.


(-3..5).toseq.filterIt(it > 0).mapIt(it * it).max()
# gives you 25


Run

did you noticed that I've converted a `Hslice` to a `seq` in order to operate 
on it? ( **first problem** )

**another problem** is that it creates intermediate `seq` s. to demonstrate 
steps for above code:


@[-3, -2, -1, ..., 5]  # initial seq
@[1, 2, 3, 4, 5]  # filtered seq
@[1, 4, 9, 16, 25]  # mapped seq
25  # max


Run

in this example, the code created _2_ intermediate `seq` s. in this example 
it's not very important but imagine you have a big `seq`/`range`/ ... and that 
can be both time and resource consuming.

### Meet `iterrr`

with `iterrr` you can keep almost the same style, and have the benefits of 
imperative programming.


(-3..5) >< ifilter(it > 0).imap(it * it).imax() #25


Run

which is almost identical to:


block:
  var acc = iseqInit[typeof(default(typeof(-3..5)) * 
default(typeof(-3..5)))]()
  
  block mainLoop:
for it in (-3..5):
  if it > 0:
block:
  let it = it * it
  if not imax(acc, it):
break mainLoop
  
  imaxFinalizer acc


Run

### Features

 custom ident

you can have other names rather than `it`.


(-3..5) >< ifilter[n](n > 0).imap[n](n * n).imax()

"hello".pairs >< ifilter[indx, c](indx > 2).imap[_, c](ord c) # [108, 111]


Run

 inline reducer


let summ = 1..10 >< ireduce[acc, n](0):
  acc += n

# summ: 55


Run

 not using reducer


1..10 >< imap(it + 1).ifilter(it > 5).do(num):
   echo num

# echos 6,7,8,9,10,11 each one in new line


Run

 define custom reducer + ...

for more information, visit the project 
[repo](https://forum.nim-lang.org/postActivity.xml#repo)


readLineFromStdin & Windows

2022-03-04 Thread hamidrb80
> stdout needs "flash"ing before getting the input, but still not sure.

yeah you're right. adding `stdout.flushFile` after line 29 solves the problem


readLineFromStdin & Windows

2022-03-04 Thread hamidrb80
> On Windows (using MSYS2

it works fine on powershell and CMD


Nim's way to clear empty character variable

2022-03-04 Thread hamidrb80

u  = char.default


Run


Why don't build Nim libraries ecosystem on Rust ecosystem?

2022-01-13 Thread hamidrb80
question: why would you wrap a rust library if you lose rust's safety? :-/


Advent of Nim 2021

2021-12-01 Thread hamidrb80
i put my solutions here: 
/

i also put Persian Translation here: 



asyncmacro.nim(130, 3) Error: 'yield' only allowed in an iterator

2021-10-23 Thread hamidrb80


is a good place to start writing `async` code in nim


asyncmacro.nim(130, 3) Error: 'yield' only allowed in an iterator

2021-10-23 Thread hamidrb80
hey, you probably know that `await` transforms to some block of code that 
contains `yield`;

you can use await only in a proc that has `async` pragma.

the possible solution here is using `waitfor` INSTEAD of `await` when you're 
not in an `async` proc


Is there a way to write tests & benchmarks for functions operating on NimNode?

2021-06-25 Thread hamidrb80
maybe it's not a good idea but I put my tests inside a macro. and then i call 
that macro

it doesn't compatible with `unittest` but it's better than nothing.

example


macro test1 =
  let
nl1 = quote: command 1 "arg2"
nl2 = quote:
  command
  1
  "arg2"
  
  let res = flattenDeepCommands(nl1) == nl2
  if not res:
warning "flattenDeepCommands(nl1) == nl2"

test "macro utils test #1":
  test1()


Run


Issue when deploying a application with Nginx as a reverse proxy!

2021-06-04 Thread hamidrb80
I get it! Nginx is itself async and create file descriptor for its async calls,

Using asyncHttpServer with nginx causes lots of opened file descriptors and 
server crashes... 


Issue when deploying a application with Nginx as a reverse proxy!

2021-06-04 Thread hamidrb80
I think it's good to try this solution. Then tell us the result