unexpected output

2024-08-26 Thread DMisener
Here is some background material which might help. Even though on a python site... still applicable. [Floating-Point Arithmetic: Issues and Limitations](https://docs.python.org/3/tutorial/floatingpoint.html)

Possible issue with getting the starting address of a Nim string

2024-08-26 Thread DMisener
re: result.setLen(ms.size) doesn't compile with experimental:strictDefs anyway (the default for the Nim compiler itself). Run Interesting... I would have thought the implicit _result_ was defined at proc invocation...so I'm not sure of the purpose of the generated

Possible issue with getting the starting address of a Nim string

2024-08-26 Thread DMisener
Does any body besides me think the following code should output an empty string? import memfiles var memSlice: MemSlice echo '"', memSlice, '"' Run instead of the following error: /Users/dennismisener/work/Nim/test.nim(3) test /Users/dennismis

UncheckedArray and closure issue

2024-08-18 Thread DMisener
**Araq** : Start by not capturing elements in: (index.with_length length).sort do (a, b: int) -> int: elements[a].cmp elements[b] Run Before **janAkali** 's kind help. .. I resorted to the **temporary copy hack** in the above code. I just thought there should b

UncheckedArray and closure issue

2024-08-18 Thread DMisener
Thanks! That does eliminate the problem. In my production code vs the above exemplar **elements** is indeed memory safe. The results of incorporating it into my production code was interesting... I thought replacing the indirect sort using a **seq** copy to/from would speed things up. **Apparen

UncheckedArray and closure issue

2024-08-17 Thread DMisener
As a followup to **How to sort dynamically allocated wordlists -- Sorting UncheckedArray type** (): I am trying to use **UncheckedArray** types to support dynamic runtime dimensionality for **arrays** to avoid the overhead of **seqs**. How do I avoid the ref

How to sort dynamically allocated wordlists -- Sorting UncheckedArray type

2024-08-17 Thread DMisener
Thanks... that was very helpful. I played around with the following playground. I think I understand it. Now to integrate into production code. proc createUncheckedArray(n: int): ptr UncheckedArray[int] = cast[ptr UncheckedArray[int]](cast[pointer](alloc(n * sizeof(int

How to sort dynamically allocated wordlists -- Sorting UncheckedArray type

2024-08-16 Thread DMisener
Background: I have a 3,000,000 entry unsorted **word2vec** model (_each word has a 300 floating point vector_). I have to sort this wordlist in alphabetic order and also reorder the associated vectors to allow binary search lookups of _word - > vector_ The problem is that I can't seem to write

How do I emulate ruby's super() for a subclass object's constructor.

2024-05-04 Thread DMisener
Thanks @SolitudeSF: I'm going to file away that _defaulting the Type_. Nice!

How do I emulate ruby's super() for a subclass object's constructor.

2024-05-02 Thread DMisener
The generics approach seem a a little less straightforward and makes constructing a Parent a little more awkward (see below): type Parent = ref object of RootObj parentField: int Child = ref object of Parent childField: string block:

How do I emulate ruby's super() for a subclass object's constructor.

2024-05-02 Thread DMisener
Thanks @doofenstein... that works just fine and requires no _magic_. I like it 🙂 I also really appreciate the feedback on _Obj_ suffix. The resulting exemplar now looks like: type Parent* = ref object of RootObj parentField: int Child* = ref object of Pare

How do I emulate ruby's super() for a subclass object's constructor.

2024-05-02 Thread DMisener
Sorry for such a basic OOP type question in advance. How do I emulate Ruby's _super()_ for a subclassed object's constructor? * When I create a _child_ object via _newChild()_ , I want the childs parent constructor _newParent()_ to be invoked to define the parent specific fields. * The d

Help storing *reference* instead of copy in an object constructor.

2024-04-28 Thread DMisener
Thanks ... I think I've got it.

Help storing *reference* instead of copy in an object constructor.

2024-04-28 Thread DMisener
Thanks @jrfondren for your thoughtful and complete response. It was certainly above and beyond the call of duty!. I tried all of the proposed alternatives and will be updating my production code code with option #2. I've include a little _test harness_ in case anyone wants to further play even

Help storing *reference* instead of copy in an object constructor.

2024-04-28 Thread DMisener
Thanks @ElegantBeef Thanks @ElegantBeef] I keep forgetting > *Nim has **no** mechanism to safely reference a value type There is probably a excellent reason for this. Perhaps my mental model about memory types is incomplete :-( I thought: * _Managed_ memory references were tracked/updated t

Help storing *reference* instead of copy in an object constructor.

2024-04-27 Thread DMisener
How can I change **initThing** so that it stores in **list** a _reference_ to **original** so that when **original** is changed, **list** reflects the change. The current code just makes a copy :-( var original = @[1, 2, 3, 4, 5] type Thing = object # I would

Nim implementation of Ruby tap() method

2024-04-24 Thread DMisener
Thanks ... looks like I reversed the working and non working version above...

Nim implementation of Ruby tap() method

2024-04-24 Thread DMisener
## Problem: * A second invocation causes error because of **{.inject.}** INim 0.6.1 Nim Compiler Version 2.0.4 [MacOSX: amd64] at /Users/dennismisener/.nimble/bin/nim nim> template tapIt*[T](obj: T, code: untyped): T = block: let it {.inject.} = obj

Nim implementation of Ruby tap() method

2024-04-24 Thread DMisener
This last one is the winner!! It feels more nim'ish and better still gives me an excuse to use the word _anaphoric_ 🙂 Yes I did overcomplicate it -- I used the **var** since I thought I might want to mutate the input... probably a bad practice anyways. Thanks It always so simple **once you

Nim implementation of Ruby tap() method

2024-04-24 Thread DMisener
Would you mind sharing the source code for **debugs**? I'm curious to see how it was done. Thanks

Nim implementation of Ruby tap() method

2024-04-24 Thread DMisener
## I would appreciate a Nim implementation of Ruby's **tap()** method. This is one of those _little helper_ functions I miss from my old Ruby days, where **tap()** : Yields self to the block, and then returns self. The primary purpose of this [method](https://apidock.com/ruby/Object/method) is

Help with macro/template extrapolating of parameters

2024-04-12 Thread DMisener
Thanks @Vindaar and @jyapayne... I can't keep up! 🙂 I was still mapping @Vindaars suggestion into a more general **Lazy** template and @jyapayne anticipated my desire to reduce the redundant boilerplate even further! I will try to add his latest refinements to what I currently have.

Help with macro/template extrapolating of parameters

2024-04-11 Thread DMisener
I've wasted more time than I'd like to admit trying to: Fabricate a simple macro or template to reduce the tedious boilerplate code required to setup up lazy ( deferred i.e. only define on first access) object fields. My stumbling block is extrapolating untype parameter data into valid Nim acc

Can ref variables reference non-ref variables?

2024-02-26 Thread DMisener
Thanks... re-reading the docs and reading your _excellent_ blog article convinced me to recode existing source to add more ref types so then I won't have to worry about trying to generate safe-references to non-ref types (doing the impossible :-) ). Thanks for the confirmation that _" you can't

Can ref variables reference non-ref variables?

2024-02-26 Thread DMisener
The following example _almost_ works but I seem to be missing the **magic incantation** to get a **safe** reference to a _non-ref_ content. The following examples illustrates my conundrum: # I am trying to generate record references of already existing objects in sequence # (as

Template default parameters question

2024-02-07 Thread DMisener
Thanks ... Very nice improvement. Using a macro to work around _trailing block parameter_ messing with other template parameter defaulting is clever. Since template parameter defaulting works fine when no trailing block parameter is specified... effectively hiding that parameter from the compil

Template default parameters question

2024-02-05 Thread DMisener
Excellent suggestion @janAKali... that indeed does the trick ( _and without much extra cruft_ ). I only wished I had thought of it :-)

Template default parameters question

2024-02-05 Thread DMisener
So it is the last untyped **actions** parameter which is causing the problem? **Changing the top example:** var lastGreeting: string template greet*(lastGreeting: untyped, text = "Hello", who = "Bob", actions: untyped) = lastGreeting = text & " " & who ac

Template default parameters question

2024-02-05 Thread DMisener
I already tried that also thinking that it would work... but adding ... template webSession*( sessionInfo: untyped, baseUrl: string, actions: untyped ) = webSession(sessionInfo, baseUrl, Chrome, false, actions) # But actually trying to use

Template default parameters question

2024-02-04 Thread DMisener
I am obviously missing something here regarding optional defaulted parameters using templates: # Defaulting is supported in the following (even when there is an untyped parameter) var lastGreeting: string template greet*(lastGreeting: untyped, text = "Hello", who = "Bob

subclassed Iterator dispatch question

2024-01-24 Thread DMisener
Thanks **Calonger** Very clever! Wrapping the _non-dispatchable_ **iterator** in a _dispatchable_ **method** makes so much sense.

subclassed Iterator dispatch question

2024-01-23 Thread DMisener
Thanks for the quick response. Not the answer I was hoping for for but we don't want to shoot the message :-) Followup questions: * Is there a recommended best practice for handling this type of situation? * Maybe there a way of getting the actual _dispatch_ type (since _object_ **of** _kin

subclassed Iterator dispatch question

2024-01-23 Thread DMisener
Question: How do I dispatch the appropriate **iterator** for an subclassed object? The following is a simple exemplar to clarify: ( _in the real world where would be many more subclass types_ ) We have two objects: ( **one** and **two** ) which are inherited from a common class ( **Number** )

New OSX weirdness - extraneous ld warning

2023-09-20 Thread DMisener
Thanks for the reminder. A great tip for adding visibility for troubleshooting such issues. **Note:** I just disocered that **—listCmd** is considered a _hint_ and therefore doesn’t show up if you have a _—hints:off_ in your **config.nims** file.

New OSX weirdness - extraneous ld warning

2023-09-19 Thread DMisener
Starting yesterday I now get the following warning when I comple any code with an import: nim c temp.nim ld: warning: ignoring duplicate libraries: '-lm' Run ## Simple Example (with import) import strutils if isMainModule: assert "A" &

Given an enum how do I return a seq of its elements

2023-09-19 Thread DMisener
Still not seeing how to do the above using **set**. The minimal prefix matching would seem to exclude it as a potential data structure.

Given an enum how do I return a seq of its elements

2023-09-18 Thread DMisener
My intended use was to utiliize an enum list in user input validation. Returning an enum allows readable conditions without the overhead of string comparision. \-- _probably overkill given my potential use-cases :-)_ import sequtils, strutils type OneOfException*

Given an enum how do I return a seq of its elements

2023-09-17 Thread DMisener
Much better than the GPT 3.5 I had access to!

Given an enum how do I return a seq of its elements

2023-09-16 Thread DMisener
Thanks again for clarifying… Everything you say, is supported by reading deeper in the docs… but hard to find the appropriate docs when you don’t know the term to look up :-(. Documentation that could read minds sure would be nice!

Given an enum how do I return a seq of its elements

2023-09-16 Thread DMisener
Thanks... that does it! In my various iterations I knew about sequtils/toSeq but what I missed was the **_items_** I find it interesting that import sequtils type Colors = enum red green blue type Colors* = enum red

Given an enum how do I return a seq of its elements

2023-09-16 Thread DMisener
For example: # Given an enum how do I return a seq of its elements type Colors = enum red green blue var colors: Colors # Expand Type to its enumerated items func toSeq[T](enumType: T): seq[T] = for item in enumType.ty

Nimble newbie issue

2023-09-12 Thread DMisener
No need to be sorry… But you did dispell my notion that you were omniscient :-)

Nimble newbie issue

2023-09-11 Thread DMisener
Would you/anyone happen to have a link to release notes, or some other artefact that I should have reviewed before upgrading to V2 and its associated toolset? I’ve had so few problems with backwards compatibility to-date that I think I’ve become quite complacent / lazy :-( I can’t be the only o

Nimble newbie issue

2023-09-10 Thread DMisener
Thanks... see my recent update for a little more clarification. The anomally seems center on nimble installs from earlier and currrent version of Nim/Nimble ... ( _Which does seems very unlikely_ since no-one else is having this issue)... but maybe you can find the _hole_ in analysis to date. I

Nimble newbie issue

2023-09-10 Thread DMisener
Thanks Araq. $home isn't oddly isn't defined my zsh shell: echo "*${home}*" ** Run I tried try creating a nim.cfg in my home (/Users/DM) directory with nimblepath="/Users/DM/.nimble/pkgs2/" Run ( _BTW there wasn 't already one_) and it

Nimble newbie issue

2023-09-10 Thread DMisener
Thanks... your are very correct...but I as reported above... that doesn't work for me either. In desperation I manually relocated the installed files from **...pkgs2** to **~/.nimble/pkgs** and ... inim đź‘‘ INim 0.6.1 Nim Compiler Version 2.0.0 [MacOSX: amd64] at /usr/local/b

Nimble newbie issue

2023-09-10 Thread DMisener
Thanks. I tried that too. But no luck. inim đź‘‘ INim 0.6.1 Nim Compiler Version 2.0.0 [MacOSX: amd64] at /usr/local/bin/nim nim> import db_sqlite /private/var/folders/8l/vhg5vggj04g77ny91mlgzn68gn/T/inim_1694328954.nim(8, 8) Error: cannot open file: db_sqlite

Nimble newbie issue

2023-09-09 Thread DMisener
# Problem: * I do my Nim development in a directory _/Users/DM/work/trunk/nim_. * If from that directory, I use nimble to install a module. > * **it does install, but I am not able to import it** :-(. * Any pointers/suggestions would be truely appreciated. - Example:

How to pass an optional callback to a proc

2023-09-07 Thread DMisener
Excellent! ... Thanks ... I prefer the **isNil** to the **option** alternative... less syntactic clutter. I will be using that little piece of knowledge going forward. See my revised code above and let feel free to comment on any other _ergonomics and preference_ related suggestions. I really d

How to pass an optional callback to a proc

2023-09-07 Thread DMisener
Thank you very much for the excellent explanation. It all makes so much sense now. I combined **PMunch** 's suggustion plus a small variant of your second option. to yield: type Callback = proc(name: string, length: int) TestOptions = object name: string

How to pass an optional callback to a proc

2023-09-06 Thread DMisener
Given the following examplar: import std/options type Callback = Option[proc(name: string, length: int)] TestOptions = object name: string length: int callback: Callback proc show(name: string, length: int) = echo "Cal

How to pass an optional callback to an a proc?

2023-09-06 Thread DMisener
Given the following examplar: import std/options type Callback = Option[proc(name: string, length: int)] TestOptions = object name: string length: int callback: Callback proc show(name: string, length: int) = echo "Cal

Dash docsets now available

2023-08-31 Thread DMisener
Thanks for this **great** resource. My previous one was getting quite long in the tooth :-)

Re: std/Paths - Converting Path to string

2023-08-25 Thread DMisener
I noticed the following anomaly: import std/paths nim> let path = Path "/dir/root.ext" nim> echo $path Error: type mismatch Expression: $path [1] path: Path Expected one of (first mismatch at [position]): [1] func `$`(x: float | float32): string

\suggestions on handling \destructuring of array/seq into a list of named fields?

2023-08-16 Thread DMisener
Thanks **cblake** & **choltreppe** : I went with a slightly tailored version of **cblake** 's first macro. * assume already existing _vars_ * pad with empty strings if too view items macro to[T](values: openArray[T], fieldNames: varargs[untyped]): untyped = result = newS

\suggestions on handling \destructuring of array/seq into a list of named fields?

2023-08-15 Thread DMisener
# Considering: # Any suggestions on handling common problem destructuring of # array/seq into a list of named fields? # (This is quite common when parsing CSV's and the like) import strutils var first, last, phone: string # usually many more fields

DumpIncludes - See where your exe size comes from.

2023-02-01 Thread DMisener
# Does _dumpincludes_ work for OSX? > Nim Compiler Version 1.6.10 [MacOSX: amd64] Compiled at 2022-11-21 Copyright > (c) 2006-2021 by Andreas Rumpf active boot switches: -d:release > -d:nimUseLinenoise ## For the following source import algorithm, itertools, sequtils, times

Nimble is unable to download and install

2022-10-25 Thread DMisener
Seems to work fine for me: âžś trunk git:(master) âś— nimble --verbose install polymorph Reading official package list Downloading using git Cloning latest tagged version: v0.3.1 Verifying dependencies for polymorph@0.3.1 Installing polymorph@0.3

if-else VS case-else VS case

2022-08-04 Thread DMisener
Using **bency** benchmarking tool -- I get: nim git:(master) ✗ nim r -d:release test_case.nim name ... min time avg timestd dv runs if-else ... 20.048 ms 20.724 ms±0.370 x241 case-else ...

How to avoid memory capture violation during addExitProc capture?

2022-05-23 Thread DMisener
Thanks... the previous **casting** version did work... but certainly had a **bad smell** to it :-). I think I'll steer clear of the **ref parameters** for now in my pure nim code... It's probably contraindicated except for mixed language interop type code?? I had tried many iterations before po

How to avoid memory capture violation during addExitProc capture?

2022-05-22 Thread DMisener
Thanks... your explanation was indeed helpful. It now seems to work :-). The _reference casting_ I used to get the closure capture working seems a bit awkward. Any suggestions for improvement would be appreciated. import flatty, std/[exitprocs, os, times] type History

How to avoid memory capture violation during addExitProc capture?

2022-05-22 Thread DMisener
I'd like to implement a simple {.persistence.} template macro ... but I can't even get the following hardcoded version to run without resorting to removing _history_ as a parameter (i.e. just including it as a global). While that works... it isn't particulary _re-use_ friendly :-(. Any better s

Hopefully simple Nim syntax question

2022-04-14 Thread DMisener
Thanks… mystery solved… As to why the compiler doesn’t realize it is being passed into a proc requiring a _var_ and accommodating is interesting.

Hopefully simple Nim syntax question

2022-04-14 Thread DMisener
Probably very simplebut stumps me :-( Any explanation would be appreciated... * * * Why is line 25: lastStoneWeight(weights.mapIt(Stone(weight: it)).toHeapQueue) Run not equivalent to commented out lines at 23-24: var stones = weights.mapIt(Stone(we

Simple linked list questions: Correct proc signature for first()

2022-03-18 Thread DMisener
Araq>Shouldn't this be ... Proc first[T](list: SomeLinkedList[T]): SomeLinkedNode[T] = result = list.head Run Probaby... but I really didn't want the now extraneous _next_ from the _source_. My implementation is less than ideal since it always allocates a new no

Simple linked list questions: Correct proc signature for first()

2022-03-17 Thread DMisener
Thanks you very much. Yoy were correct on both counts. BTW: I also found another bug. My initial version _accidently_ mutated in the source! I finally ended up with: proc first[T](list: var SomeLinkedList[T]): SomeLinkedNode[T] = let node = list.head result = node

Simple linked list questions: Correct proc signature for first()

2022-03-17 Thread DMisener
The solution is probably painfully simple to everyone but me :-( Just trying to model [Lisp's CAR, CDR](https://www.gnu.org/software/emacs/manual/html_node/eintr/car-_0026-cdr.html) functionality. import lists proc firstDbg(list: var SomeLinkedList) = var node = list

How to correctly augment async future data

2022-02-28 Thread DMisener
Yes... Thanks ... that was all that was required. Such a simple change... and yet I just couldn't see it.

How to correctly augment async future data

2022-02-28 Thread DMisener
Thanks... that is pretty much what I suspected... I was hoping to collect the finish time in the callback but after the await is probably just as good.

How to correctly augment async future data

2022-02-28 Thread DMisener
Another newbie question :-( I'm still having difficulty in using async callback to update _future_ result with computed data (a time stamp in this case). ## Example code: # - How can I get access to the completion time (info.finish) when the request # has been fullfilled?

Stumped! Extending futures with addition context info

2022-02-18 Thread DMisener
Oops… forget to say thank :-) Much better/simpler! Now I have to double check that actually processes the sites asynchronously… seems to take longer that I would expect… I’ll add start and finish times to the _context_ to make sure they overlap.

Nim devroom at FOSDEM this weekend

2022-02-18 Thread DMisener
FYI: IPad and Mac play the video but no audio? Anyone else have this problem?

Stumped! Extending futures with addition context info

2022-02-16 Thread DMisener
I need a little help with extending _futures_ with additional context for error reporting. I can't even get my current effort to compile without commenting out a couple lines :-(. Any pointers would certainly be appreciated. # Background: # - Test harness to check out how to ex

New here

2021-11-03 Thread DMisener
Great non obvious recommendations.

Looking for feedback on Nim for Beginners #27 Object Variants

2021-10-25 Thread DMisener
Always a fan…. as a Nim newbie your efforts are much appreciated.

Nim access to OSX cut and paste buffer:

2021-10-15 Thread DMisener
I'm trying to avoid _costly_ shelling out to pbcopy/pbpaste. import osproc, strutils proc pbpaste() : string = var exitCode: int; (result, exitCode) = execCmdEx "pbpaste" proc pbcopy(content: string) = discard execCmd "echo " & content.replace("\"",

How to make Nim more popular

2021-08-20 Thread DMisener
Anyone besides me interested in more representation on _Coding Solutions_ forums like **Leetcode** (, **HackerRank** () and **Exercism** . The later actually is now supporting Nim!