What can Nim learn from Crystal

2024-05-19 Thread sky_khan
This is what happens when you try to use that 7 years old unmaintaned repo interfaced.nim(40, 39) Warning: Deprecated since version 0.18.1; All functionality is defined on 'NimNode'.; symbol is deprecated [Deprecated] interfaced.nim(40, 24) Warning: Deprecated since version 0.18.

gensym redeclaration

2023-11-20 Thread sky_khan
I dont know much about compiler internals but it may be related to optimization, I think. Global references are kept until exit so they're kinda const regarding to variable lifetime. Inside procedures compiler needs to keep track of assignments and refcounts and fails. Thats just a guess, I may

Question from one of my customers.

2023-11-19 Thread sky_khan
It's been 10 years since I got registered to this forum. Even then it had been around several years. Not like Google or Mozilla but it has few corporate sponsors and it has a permissive MIT license which corporate firms like to use. So I dont expect it to die soon.

Question from one of my customers.

2023-11-19 Thread sky_khan
Because, maybe, Nim can be one of most practical and productive language, depending on task at hand? It has its own drawbacks too of course but it's learning curve is not steep. If you are somewhat familiar with Python (and possibly Pascal), just a few days should be enough to make your own deci

gensym redeclaration

2023-11-19 Thread sky_khan
Your code is kinda ambiguous, not clear if you want to create two seperate sequences or two references to same sequence. Still, seems like a compiler bug to me. I mean, it should be caught at nim compilation phase.

Should conversion outside of a range result in a Defect

2023-11-17 Thread sky_khan
How about this ? import std/strutils type myRange = range[1'u8..128'u8] proc foo(x: myRange) = echo("got : ",x) #foo(129) # In my head should be a compile time error, which it is let inp = parseInt(readLine(stdin)) proc checkMyRange(value

Should conversion outside of a range result in a Defect

2023-11-17 Thread sky_khan
Its your responsibility to verify user input. If you allow out of range values you're opening the gate for invalid state and undefined behavior for your application.

How to define a =copy hook for a distinct cstring type?

2023-09-17 Thread sky_khan
AFAIK, yes it does. Nim's strings basically same as Pascal/Delphi strings. It keeps size of it in a hidden field and they're null terminated.

How to define a =copy hook for a distinct cstring type?

2023-09-17 Thread sky_khan
Sure. Still, how will your users will use cstring ? Nim standard lib, strutils, strformat.. expects Nim string. If you keep it as cstring in a Nim object, it will have to be converted to Nim string on-the-fly on every call site every time it's used. I'm just saying maybe you should consider to c

How to define a =copy hook for a distinct cstring type?

2023-09-17 Thread sky_khan
If Nim side owns the string why dont you just convert it to Nim string in the first place ? Otherwise you have to scan all cstring to query it's size every time but getting cstring pointer out of Nim string is effortless.

Inferring type of zero-sized collection from usage

2023-08-25 Thread sky_khan
That = Changing type of variable on runtime or infer type of variable to apply optimizations. Maybe because I'm old but I'd prefer to see type of variable where it's declared. I just dont see the point of this kind of inference for Nim.

Inferring type of zero-sized collection from usage

2023-08-24 Thread sky_khan
That may be possible in script languages but nim is static typed compiled language. Type of "a" variable must be known on compile time. You cant change type of variable on runtime. So why not you go and declare "a : seq[string]" anyway ? Because what you're asking has no substantial benefit.

Good Languages Borrow, Great Languages Nim

2023-05-19 Thread sky_khan
> My professor says to me "C" is 60 times bigger than "Nim", and he laughs Thats absurd! I'm sure a competent C programmer can write same software less than 10 times LOC ;)

Usability of ARC/ORC in multi threaded code.

2023-05-07 Thread sky_khan
My English is not good. Still, I will try to explain what I had in my mind a bit more before I give up. I was answering these: > Araq: How can you assume a lock on the "root" Node? The compiler has no idea > about a "root" node > > PMunch: Indeed having a rule like "every local variable involv

Usability of ARC/ORC in multi threaded code.

2023-05-07 Thread sky_khan
Sorry, maybe it was 8-9 years ago when I've last time looked nim compiler source. I'm not exactly sure what I'm talking :) but I was thinking, you have to track and store information about every assignment, every access to that data in every module to make isolated work. Compiler then would need

Usability of ARC/ORC in multi threaded code.

2023-05-07 Thread sky_khan
Most probably I'm being stupid here but cant you invent a new return type which cannot be assigned to a variable and cant be changed after returned from a proc? Then If threads:on, wouldnt it be possible to prove it that it is really not touched after its built in extra compiler pass ? proc bui

Atomic ARC

2023-05-07 Thread sky_khan
> shared ownership is heavily discouraged and it's a pain to debug [Rant] Worst CPU owner here. TBH, debugging Nim code is PITA, with or without atomicArc. Recently I've tried to write an utility in Nim. I'm a hobbyist, an old one. I make a lot of mistakes during prototyping and I often get lost

Atomic ARC

2023-05-06 Thread sky_khan
Hint: mm: arc; threads: on; opt: speed; options: -d:release 176527 lines; 6.574s; 609.012MiB peakmem; Hint: mm: atomicArc; threads: on; opt: speed; options: -d:release 176527 lines; 7.462s; 609.34MiB peakmem; i7-6700K ddr4 2666

Can I quick get table last key value use like at(idx) function?

2023-04-24 Thread sky_khan
Its not that simple. Capacity != Count in underlying table. Still, IMO this should be in tables.nim. Its not ideal but better than nothing. proc raiseIndexError(ndx, max : int) = raise newException(IndexError, "index " & $ndx & " not in 0.." & $(max-1)) proc keyAt*[

Can I quick get table last key value use like at(idx) function?

2023-04-24 Thread sky_khan
Table in Nim is hash table. Its not like sequences. Order of items is not guaranteed.Hypothetically, OrderedTable could have what you want but it has not. You have to change your algorithm or look elsewhere

EU Cyber Resilience Act impact on Open Source community

2023-04-22 Thread sky_khan
Well, I've tried but one of first links in google search tells how important its for cyber security for pages, without giving me a link to real thing. Besides, I've looked python foundation's page where it says, "In particular, we believe that th

EU Cyber Resilience Act impact on Open Source community

2023-04-22 Thread sky_khan
Not sure if they're just stupid or if they want to kill open source software in Europe because thats how you kill open source. Nobody would contribute to anything if there is a chance you may get sued without getting paid.

Scan syntax tree for procedure calls

2023-04-10 Thread sky_khan
I see but I've done some database work back in the days. If you keep business logic on application side you often need reading from database too in your write transactions for enforcing rules etc. I think something like this is a possible use case: db.startTransaction(t): rea

Scan syntax tree for procedure calls

2023-04-10 Thread sky_khan
I dont know that database but how about this : type Transaction = object active : boolean handle... etc db.startTransaction(t): write or read db commit (/ rollback) #which beginTransaction(t) translates as below and commit/r

Save audio stream to the file from httpstream

2023-02-21 Thread sky_khan
Well, I dont really know Nim well. Actually I havent used it at all for the last few years. I just visit the forum sometimes to follow the news. Anyway, this time I've tried to download from those URLs with wget. It says request sent, awaiting response... 200 OK Length: unspec

Save audio stream to the file from httpstream

2023-02-20 Thread sky_khan
Ok then, just an advice. Never ignore error codes or swallow exceptions (at least make that discard an echo) unless you have a really good reason. Probably you're getting some other error without knowing it

Save audio stream to the file from httpstream

2023-02-20 Thread sky_khan
I've just selected that radioURL and opened in new tab. It gives 404 error. So its not a surprise that bodyStream has no data.

Seq too big I think Error: execution of an external program failed

2022-11-18 Thread sky_khan
Well, it may be out of memory error but there must be a logic error somewhere or your desktop must be a potato with 1-2GB ram max :) No way filling all memory with a few thousand objects / strings. Can you share your code ?

Seq too big I think Error: execution of an external program failed

2022-11-18 Thread sky_khan
This shouldnt happen on a desktop machine. Is this thing running on a cheap VPS or something ? I guess you may add sleep(1) before entering each directory or something but its far from ideal. I have no other idea because I'm not experienced on hosting sites, sorry.

Seq too big I think Error: execution of an external program failed

2022-11-16 Thread sky_khan
How many and how big ? I mean, one million objects with 1K data on each would make a 1GB. That should be fine even with GC overhead. Are you sure you're not caught by infinite or recursive loop somewhere ?

How can I get the fields and field-types of an sqlite-database?

2022-11-11 Thread sky_khan
Sqlite is kinda schemaless, columns does not really have types. They have only declared types. You can store anything in any column. Still, you may query "sqlite_master" table but you'll have to parse DDL clause yourself

nim name origin?

2022-11-08 Thread sky_khan
AFAIR it was a reference to tower of babel because Nim aims to be the one language to rule them all

Illegal storage access

2022-07-24 Thread sky_khan
If it happens when you try to compile, thats a bug in compiler. If you can share your code maybe somebody would help to locate the bug or you may try to compile compiler in debug mode to see where it crashes.

Please help me understand the performance difference between Nim/Rust in this (contrived) example

2022-06-05 Thread sky_khan
Well, I'm not good at assembly either. If thats the case, it must be where "Rust is even faster than C" comes from :)

Please help me understand the performance difference between Nim/Rust in this (contrived) example

2022-06-05 Thread sky_khan
I'm lazy to make performance analysis. I have no Rust installed anyway. Could you try this ? type Result = object letters : int numbers : int proc analyze(x: string): Result = for c in x: case c: of 'A'..'z'

Nim v2: what would you change?

2022-04-30 Thread sky_khan
> Even tooling can't be made better because it all relies on the compiler - > e.g. nimsuggest, nim check, etc. While you're at it, can we get rid of all globals in compiler and make it an object, so it can be compiled as a dynamic library and instantiated / destroyed at will ?

Can't have correct Nim nested template. Please explain

2022-03-26 Thread sky_khan
template f(i:int)= i += 5 template g= var i : int if true: f(i) else: i += 2 echo "\ni=",i g Run

Must abruptly exit from a recursive function on efficiency Need

2022-03-04 Thread sky_khan
Not sure if you can. If you really need this, I think you'll have to rewrite it as non recursive probably by doing your own stack management yourself.

Trojan:Win32/Wacatac.B!ml

2022-01-22 Thread sky_khan
There are already some blog posts about it. So, make that a youtube video and use it as marketing opportunity with a title something like "Why virus makers use Nim" or something. Dont forget to bash AV vendors too. Just saying :)

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

2022-01-13 Thread sky_khan
Do you know its not easy to decide whether you're trolling or not ? > Did we really need to work in deep with Rust if we write just a Rust wrapper? Maybe not but... You said you're not a Nim user. Can you wrap a C library into Nim ? without knowing any of them ? Whoever wraps a Rust library mus

simple event system

2022-01-11 Thread sky_khan
No need for me but maybe others can give a fix / suggestion

simple event system

2022-01-11 Thread sky_khan
IDK, You may encounter bugs if you make a class hierarchy from EventBase as @jyapayne said but I dont think it would be 2x slower if you change it as yours. I mean, I was lazy and used type name as keys instead of hash and used sequence as container for events. That must be the reason, I guess

simple event system

2022-01-10 Thread sky_khan
Not sure if this is the best way but this seems working: import tables, typetraits type EventBase = object of RootObj EventProc = proc(ev:EventBase) {.nimcall.} EventCallback[T:EventBase] = proc(ev:T) {.nimcall.} EventReg = object

One Language to Rule the Mole

2022-01-07 Thread sky_khan
> You are saying that we should hire the designer and having him draw a series > of moles with a clunky crown that keeps falling over their eyes or through > their body Yep! Exactly. That would be fun

One Language to Rule the Mole

2022-01-07 Thread sky_khan
Okay but where is the crown ? That mole seems unrelated without one, you know :)

Why windows.h file is always included into compilation on Windows?

2021-12-12 Thread sky_khan
Not really sure if it would work (I'm not much experienced in C) but what about using --passC option of Nim to give "-include " to gcc ?

createDir on Windows using URL

2021-11-05 Thread sky_khan
No idea whats wrong with std/os but this works: import std/winlean let testFldr = "KHANDESKW\\Shared\\helloworld" let ws = newWideCString(testFldr) let r = createDirectoryW(ws,nil) if r != 0: echo testFldr & " created" else: echo "Error"

Linking on Linux and Windows

2021-10-31 Thread sky_khan
On Windows, if you have an installer, you may register your application on registry and specify [App Paths](https://docs.microsoft.com/en-us/windows/win32/shell/app-registration) for additional directories for your DLLs. That way it will work from search bar and run dialog without modifying glo

String expression parsing

2021-08-25 Thread sky_khan
I've used your problem for trying [npeg](https://github.com/zevv/npeg) out . I guess I have too much time :) Disclaimer: This is my first try using Npeg. Use at your own risk Here you're: import npeg, strutils, tables type Dict = Table[string, string] let parser =

Why does this, while incorrect, iterator( code always result in a crash of the playground?

2021-08-24 Thread sky_khan
Yes, you have an infinite loop here because i is always smaller than sum : while i < sum: inc i, 1 inc sum, i echo "i:" & $i & " sum:" & $sum# you may add this to see it yourself. Run So, It never finishes looping and it can not send a response in

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

2021-06-04 Thread sky_khan
Sounds like the same issue:

select a type

2021-06-02 Thread sky_khan
Yep, thats nicer but considering he/she had not heard of generics, I didnt want to talk about macros :)

select a type

2021-06-02 Thread sky_khan
Ok, If you're sure you need just one FileBits definition, const BitDepth = 32 when BitDepth == 8: type FileBits = uint8 when BitDepth == 16: type FileBits = uint16 when BitDepth == 24: type FileBits = uint32 when BitDepth == 32:

select a type

2021-06-02 Thread sky_khan
You cant create a type at runtime. If BitDepth is not known at compile time, you'll need all these types. Then you can use generics, I guess

"Error: unable to set ODBC driver version." with db-odbc

2021-02-18 Thread sky_khan
It was long time ago I've used ODBC but I'm sure ODBC connection string format is not the same as JDBC. You should check ODBC/Oracle documentation for proper connection string format of ODBC driver for Oracle.

Raspberry Pi 1B - nmqtt - exit code 137

2020-11-09 Thread sky_khan
Not sure if it will work but I guess you may try giving it more swap space and much time.

Is there a way for case objects to have cases share fields?

2020-10-29 Thread sky_khan
> I also tried nkDocument, nkCanvas, but I need nkCanvas to eventually be > different from document? Not possible for now:

Nim videos and tutorials survey

2020-10-28 Thread sky_khan
Multithreading and async, tcp/http servers, karax

template expanding to multiple sequence members

2020-10-28 Thread sky_khan
Templates in Nim are not text substitutes like in C. They dont work on irregular code fragments. I'm not sure if this is possible even with macros but I'm not a macro expert.

template expanding to multiple sequence members

2020-10-27 Thread sky_khan
How about ? template myTemplate(x: untyped) : untyped = @[int(x), int(x shr 2)] var a: seq[int] = myTemplate(13) assert(a == @[13, 3]) Run

Writing binary data to SQLite

2020-10-21 Thread sky_khan
Prepared queries can be many times faster depending on use case. So, I think they should have been part of stdlib but I guess its too late for v1. Here is what I meant by "diving into sqlite3.nim" import sqlite3, db_sqlite, strutils, strformat let dbname = ":memory:" le

Writing binary data to SQLite

2020-10-20 Thread sky_khan
AFAIK, you can insert blob values only by converting them to hexadecimal using sql, unless you're using prepared statements. Last time I checked db_sqlite.nim in stdlib had no support for prepared statements. You should dive into low level wrapper sqlite3.nim or find another library which suppor

High proc confusion

2020-09-07 Thread sky_khan
> if you conceive of high as "seq.length minus 1" it's gonna get confusing I believe seq is designed as (can be thought of) Nim's runtime resizable array anyway. So, It makes sense to me that high returns highest value for types and highest index for arrays (and containers). I've learned Pascal

High proc confusion

2020-09-07 Thread sky_khan
> I assume that if I can use High on a value then I get the value - 1 and if I > use High on a ordinal type I will get highest ordinal of this type. Simple as > that. Even if I try to think like you... Why ? If 60 could get the value of 60 why should high(60) return 59 ? It is a

High proc confusion

2020-09-06 Thread sky_khan
var index = 600_000 .. is same as .. var index : int = 600_000 int type is inferred and "high" returns highest value of int type, as expected. if you need smaller range than int, well, use a range, like type MyInt = range[0..1_000_000]

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

2020-08-11 Thread sky_khan
Nim is not (kinda) typeless as C. You cant assign integer values to a char variable directly in Nim. So, if you declare it's parameters as char, you would have to convert your integers to char like rgb(chr(255),chr(0),chr(0))

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

2020-08-11 Thread sky_khan
Because rgb("w","t","f") doesnt make sense :)