Why `using` not working? Bug?

2021-08-17 Thread alexeypetrushin
Thanks! I knew that, constantly forgetting about this semicolon thing!

Why `using` not working? Bug?

2021-08-17 Thread alexeypetrushin
Strange, it should work but it doesn't [playground](https://play.nim-lang.org/#ix=3wkc) type O* = object using tself: type[O] proc init*(tself, v: int): O = discard proc init*(tself, v: string): O = O.init(1) Run Error

Why `using` not working? Bug?

2021-08-17 Thread Yardanico
You need to use the semicolon to separate `tself` from the rest since otherwise it means that you want `type[O], v: int` which is incorrect. type O* = object using tself: type[O] proc init*(tself; v: int): O = discard proc init*(tself; v: string): O =

A look at Dart's null safety syntax

2021-08-17 Thread ElegantBeef
Works fine once you call the correct map: import sugar, sequtils import std/options except map converter to_option*[T](t: T): Option[T] = some(t) template pick*[T](list: openarray[T], field: untyped): untyped = list.map((v) => v.`field`) echo @[(n

Confusion about `swap`

2021-08-17 Thread Kalbhairab
is there any python like syntax for swap a,b=b,a and a,b=b,a+b (fibonachi case)

A look at Dart's null safety syntax

2021-08-17 Thread alexeypetrushin
I tried it option autoconverter, but it doesn't work, for example this code would fail import options, sugar, sequtils converter to_option*[T](t: T): Option[T] = some(t) template pick*[T](list: openarray[T], field: untyped): untyped = list.map((v) => v.`field`

A look at Dart's null safety syntax

2021-08-17 Thread jasonfi
Using ? to specify an option type isn't inconsistent or implicit. It's just a shorter syntax.

A look at Dart's null safety syntax

2021-08-17 Thread ElegantBeef
Comically I do not, since it introduces a converter and introduces that rather esoteric unary operator, but as a showcase of why this forum post is not really needed(the language already allows the desired behaviour) it's golden! :P

A look at Dart's null safety syntax

2021-08-17 Thread treeform
Wow Beef, I really like your extra option extensions. It looks way better normal Options.

Nim for UI Automation

2021-08-17 Thread Lecale
I've been using Nim a little in work for some simple UI Automation. A little bit of and a little bit of replaced some outdated C# Webdriver code. I felt a bit old hat using UIAVerify, but it

Change error message position using `{.line.}` pragma

2021-08-17 Thread haxscramper
Because I'm an idiot. I just thought about the most obvious solution literally squashing files together), and using import/include just didn't occur to me

Wrapping cpp code

2021-08-17 Thread Cnerd
Thanks

Wrapping cpp code

2021-08-17 Thread Stefan_Salewski
I think it is not that hard to guess what the macro does. First line checks if NDILIB_CPP_DEFAULT_VALUE is not defined. When you convert to Nim code this is generally true (undefined.) Next line checks if we compile in cpp mode. If that is the case (I would guess yes) then the macro call NDILIB_

A look at Dart's null safety syntax

2021-08-17 Thread xigoi
I like consistent syntax. `int?` is unnecessary inconsistency, just like `int[]` and `int*` (and whatever other syntax for a built-in generic type you can come up with).

Wrapping cpp code

2021-08-17 Thread Cnerd
Hello i was using c2nim to try to convert a group of header files to nim but some code where omitted. Now this is not to much of a problem because i was able to fix most of them on my own. But i am no expert in c or cpp so there are some lines of code i could not convert because i do not underst

A look at Dart's null safety syntax

2021-08-17 Thread xioren
I prefer Nims explicitness. String? abc; Run Makes me cringe.

A look at Dart's null safety syntax

2021-08-17 Thread JohnAD
I don't have answers. I have no problem with the Option[T] method used by Nim myself. But, has a whole, most languages have a hard time differentiating between four completely different concepts: `nil`: memory is not allocated; a C term. `null`: per SQL and other definitions, this means "unkno

Puzzle questions and solutions

2021-08-17 Thread auxym
Well there's Rosetta Code, and Exercism's Nim track. Many people also have solution repos for Advent of Code.

Confusion about `swap`

2021-08-17 Thread Araq
It's a bug. :-) This works: from algorithm import fill type O = object a: array[9, int] proc swapper(arr: var O) = #let oldaddr = arr.addr var support: O support.a.fill(1) #echo arr.addr == oldaddr swap(support, arr)

A look at Dart's null safety syntax

2021-08-17 Thread alexeypetrushin
A typing mistake, I meant the union types for for primitive types (at least for primitive types, ideally for any type). Exhaustive Type Checking. Compile type checking for correct usage of union types in if/switch/return statements and functions. function makeDessert( fruit: 'banan

A look at Dart's null safety syntax

2021-08-17 Thread geohuz
I'm guessing he is asking for ocaml/resonml syntax like: type schoolPerson = Teacher | Director | Student(string); let greeting = person => switch (person) { | Teacher => "Hey Professor!" | Director => "Hello Director." | Student("Richard") => "Still h

Change error message position using `{.line.}` pragma

2021-08-17 Thread demotomohiro
> I need to merge multiple nim files in a single one in order to compile > everything at once, May I ask why you need to do that? Why you cannot use import/include statement?

Puzzle questions and solutions

2021-08-17 Thread demotomohiro
answer: import math func f(n: Natural): Natural = fac(n) Run

Puzzle questions and solutions

2021-08-17 Thread Kalbhairab
This is a great forum to get response quickly. If this forum have any category to ask for questions and get answer. Let's say: A puzzle to calculate factorial of x. A factorial is a function that multiplies a number by every number below it. For example 5!= 5*4*3*2*1=120 Create a function to c

Confusion about `swap`

2021-08-17 Thread Xaco97
Hi, I was experimenting with the `swap` proc of the `system` module ([here's the doc](https://nim-lang.org/docs/system.html#swap%2CT%2CT)) since I need it in a uni project and I encountered a behavior that confuses me. If i go to the [Nim Playground](https://play.nim-lang.org/) and I execute the

convert func to property box

2021-08-17 Thread Kalbhairab
It is not my point. My point is to get all the items of function and its output. Suppose function is proc add(a,b: int):int = a+b I should get variables a, b and add(a,b). Its implementation will be We get Input a b Output a+b It should read variables of function and give input as guidance prop

simple connection GET using httpclient does not work when compiled to js

2021-08-17 Thread samsamros
this is really good stuff. I'll take a look... reading the pull request's comments, and running through the other links. I'm gonna download it and play around with it. Thanks. I'll get back to you to let you know... Def upvoting on github

simple connection GET using httpclient does not work when compiled to js

2021-08-17 Thread samsamros
thanks... I thought of that too, but was looking a way to communicate more directly to the js backend... but this is absolutely worth a try.

simple connection GET using httpclient does not work when compiled to js

2021-08-17 Thread xflywind
httpclient doesn't support JS backend. One of solutions is

simple connection GET using httpclient does not work when compiled to js

2021-08-17 Thread enthus1ast
Or just wrap the native js functions

simple connection GET using httpclient does not work when compiled to js

2021-08-17 Thread samsamros
Hello all I'm delving into Nim and its amazing characteristics. I'm trying out a simple API connection, but when compiling to javascript I get this:/usr/lib/nim/pure/ssl_certs.nim(75, 32) Error: this proc is not available on the NimScript/js target; usage of 'walkFiles' is an {.error.} defined a

newbie kick-in-the-pants: nim as a cgi application

2021-08-17 Thread enthus1ast
I like to use NSSM / for a more systemd like feeling ;)

A look at Dart's null safety syntax

2021-08-17 Thread Araq
> And, to complete the story, primitive union types (with compiler support for > exhaustive if/switch etc.) also in many cases are better than enums :) What does that even mean...

Server Sent Events?

2021-08-17 Thread ingo
So I missed one. Thanks, I'll have a look.

Change error message position using `{.line.}` pragma

2021-08-17 Thread haxscramper
I need to merge multiple nim files in a single one in order to compile everything at once, but I also need to have a correct stacktrace and compilation error information that points to the _original_ file location (i.e. in one of the files I concatenated). I can get correct stacktrace using `{.

Server Sent Events?

2021-08-17 Thread alexeypetrushin
I implemented Pub/Sub around SSE in Nim [clock example](https://github.com/al6x/nim/tree/main/ws/examlpes) in Nim, although I'm currently don't use it. As it feels less reliable than Node.JS.

A look at Dart's null safety syntax

2021-08-17 Thread alexeypetrushin
Yes `T | nil` is superior to `Option[T]`, in pretty much every use case, from optional variables to optional func args.

Server Sent Events?

2021-08-17 Thread ingo
How would one create a minimal client for listening to an SSE stream? var client = newHttpClient() var response = head(client, url="https://stream.wikimedia.org/v2/stream/recentchange";) echo response.headers Run the code above seems to get stuck for `get` as w

A look at Dart's null safety syntax

2021-08-17 Thread Vindaar
But no information by intent is not equal to no information by default! In the same way as mathematics contains the notion of an empty set as 'something'. Consider a string representing a title. You may wish to provide a default title if the user does not give a title manually. But there may be

html tags from template not being rendered

2021-08-17 Thread enthus1ast
You could also have a look at nimja templates, they work quite similar, but look more like jinja or twig.

A look at Dart's null safety syntax

2021-08-17 Thread jasonfi
Could you give an example of this please?

A look at Dart's null safety syntax

2021-08-17 Thread adrianv
When you look at a `string` as a _value_ , I don't like to distinguish between `null` and `""` \- `null` means always the absence of information and a empty `string` carries no information. Hiding this inside an option does not help unless you really need to distinguish these cases.

newbie kick-in-the-pants: nim as a cgi application

2021-08-17 Thread martin
indeed. so far i managed to create a few tools manipulating with database and they are bloody fast compared to php. My problem specifically lies in the environment - windows server: scheduler is unreliable, automatic updates which change the environment largely unpredictably. I need a tool I ca

A look at Dart's null safety syntax

2021-08-17 Thread Araq
> Going back to Nim I see my code is full of "some" and "none" keywords, where > as Dart tries to minimize this syntax. I usually store the "none" indicator elsewhere and avoid `Option[T]`. It works much better because `op(T)` doesn't have to be lifted to `op(Option[T])` everywhere.

A look at Dart's null safety syntax

2021-08-17 Thread ElegantBeef
I don't know what the first point means, but to the second it's not a postfix but the following works. import std/options template `?`(a: typedesc): typedesc = Option[a] converter toOpt[T](t: T): ?T = some(t) var abc: ?string if abc.isNone: abc = "test"

A look at Dart's null safety syntax

2021-08-17 Thread jasonfi
Explicit is better, true, but minimizing syntax can also make code more readable.

How to respond to a key event in Jester?

2021-08-17 Thread jasonfi
Could that work as part of Jester? Or perhaps a Jester extension?

A look at Dart's null safety syntax

2021-08-17 Thread jasonfi
The two syntax changes I would most like to see are: 1. Assume assignment means there's a value, unless specified: 2. Use of ? as a shortcut for an option type: Put together you could write: var abc: string? abc = "testing" Run

Web app architecture?

2021-08-17 Thread martin
Great video, thanks for sharing!

A look at Dart's null safety syntax

2021-08-17 Thread Theromented
Each of us likes to receive pleasant surprises, preferably often and different ones. But here in the Golden Reels [casino no deposit bonus australia](https://goldenreels-blog.com/no-deposit-bonus-codes/) on-line casino more than receiving gifts, we love giving them away to our dear players and

A look at Dart's null safety syntax

2021-08-17 Thread mratsim
You can sprinkle converters beyond the proposal of Elegant beef until you get the syntax you want. For example converting options to bool for "more readable" if branches. Personally, I think those tricks become quickly problematic in a team setting and as the codebase grows. Not even talking ab

A look at Dart's null safety syntax

2021-08-17 Thread aEverr
i believe the "none" and "some" functions are needed because of the type system nim has

A look at Dart's null safety syntax

2021-08-17 Thread ElegantBeef
Well it's not overly complicated to make simpler. One issue is didnt use `isSome` or `isNone` for the if. There are also utility modules such as [optionsutils](https://github.com/PMunch/nim-optionsutils) to make it safer and easier to work with. import std/options converter to

A look at Dart's null safety syntax

2021-08-17 Thread xigoi
Optional types and nullable types are two different things. Nullable types have the problem that they can't be nested (like `Option[Option[T]]` and require compiler magic because they don't behave like a regular type.

newbie kick-in-the-pants: nim as a cgi application

2021-08-17 Thread alexeypetrushin
I think CGI could be actually a good use for Nim on the web, given that Nim processes are lightweight.

A look at Dart's null safety syntax

2021-08-17 Thread jasonfi
I've done some work with Dart recently, and I thought that Nim could perhaps benefit from a look at their approach to null safety: You can read about it here: The syntax is so much better, in my opinion, as it is more minimal. For example in Nim you'd write: