ChanServ changed the topic of #picolisp to: PicoLisp language | Channel Log: https://irclog.whitequark.org/picolisp/ | Check also http://www.picolisp.com for more information
orivej has joined #picolisp
orivej has quit [Ping timeout: 256 seconds]
orivej has joined #picolisp
rob_w has joined #picolisp
aw- has joined #picolisp
mtsd has joined #picolisp
<mtsd> Good morning
<tankf33der> o/
<Regenaxer> Hi mtsd, tankf33der
<mtsd> Hi Regenaxer
<beneroth> Good morning friends :)
<Regenaxer> Hi beneroth
Nistur has quit [Ping timeout: 256 seconds]
orivej has quit [Ping timeout: 240 seconds]
orivej has joined #picolisp
mtsd has quit [Quit: Leaving]
orivej has quit [Ping timeout: 260 seconds]
orivej has joined #picolisp
<joncfoo> anyone have a clue as to why function isn't recursing? I'm sure it's a silly mistake: https://dpaste.com/FFPJZD5X4
<joncfoo> I'm calling it like so: (add-word () (chop "cat"))
<joncfoo> trying to replicate the clojure version I have: https://repl.it/repls/LimpingGraciousSpools
<Regenaxer> Hi joncfoo!
<Regenaxer> (cons ((lit hd) is problematic, no?
<Regenaxer> Why two ('s ?
<beneroth> ((lit hd)) is a function call, calling the result of (lit hd)
<beneroth> so it probably segfaults there, no?
<beneroth> as the result of (lit hd) is most likely not a function body
<Regenaxer> Hi beneroth!
orivej has quit [Ping timeout: 264 seconds]
<joncfoo> no it doesn't segfault - it just returns ("c")
<Regenaxer> hmm, so is
<Regenaxer> ((lit hd) (add-word () (cdr WORD)))
<Regenaxer> supposed to be a computed function call
<Regenaxer> withe the result if add-word as arg?
<joncfoo> yes that is what I expect
<Regenaxer> (lit hd) returns the value quoted
<joncfoo> well (cons ((lit hd) (add-word () (cdr WORD)) TRIE)
<Regenaxer> yes, that's different
<Regenaxer> ah, misread
<joncfoo> if I remove the call to lit, I get a "hd -- Undefined"
<beneroth> yeah function call
<joncfoo> yea I have to quote the transient symbol
<Regenaxer> hd is "c"
<Regenaxer> so it you quote it, it is not a function
<Regenaxer> (quote . "c")
<beneroth> what is the expected result of (add-word () (chop "cat")) ?
<beneroth> btw. this is equal to (add-word NIL '("c" "a" "t"))
<joncfoo> ("c" ("a" ("t" (ok]
<joncfoo> I'm trying to build a Trie structure
<Regenaxer> ok, let me try to clean up
<beneroth> joncfoo, 'cons function is not destructive, and cons is prepending, not appending
<joncfoo> that's ok - it can be in reverse, it doesn't matter in the end
<beneroth> (if (not Word) ...) -> (ifn Word ..)
<joncfoo> +1
<joncfoo> nice shortcut
<beneroth> strongly recommend to keep to the picolisp naming convention, though it has no technical effect. Local variables starting with upper case, so hd -> Hd
<Regenaxer> yeah
<joncfoo> sounds good
<joncfoo> are function parameters supposed to be all caps?
<Regenaxer> What args are the 'cons'es supposed to get?
<Regenaxer> Not all caps
<tankf33der> joncfoo: cant open clojure code link on iphone
<Regenaxer> all caps are rather global constants
<beneroth> tankf33der, it loads forever on desktop firefox, but eventually something comes up
<beneroth> joncfoo, function parameters are basically the same as local variables :)
<tankf33der> joncfoo: you took too complex task.
<joncfoo> lol
<tankf33der> joncfoo: btw, i have 4clojure solved on picolisp:
<tankf33der> almost all.
<beneroth> Regenaxer, I think the extra () is supposed to be (list ) :)
<Regenaxer> I think it is ok, just NIL
<beneroth> Regenaxer, I mean also within the cons call :)
<Regenaxer> I just dont get what the ((lit hd) is supposed to do
<beneroth> I suspect it should be (list (lid hd) ...)
<Regenaxer> ah
<joncfoo> lid?
<beneroth> : (add-word () (chop "cat"))
<beneroth> -> (("c" (("a" (("t" (ok)))))))
<beneroth> close
<beneroth> (de add-word (Trie Word)
<beneroth> (cons 'ok Trie)
<beneroth> (let Hd (car Word)
<beneroth> (ifn Word
<beneroth> (if (not (assoc hd TRIE))
<beneroth> (cons (list Hd (add-word NIL (cdr Word))) Trie)
<beneroth> (cons (list Hd (add-word (assoc Hd Trie) (cdr Word))) Trie) ) ) ) )
<Regenaxer> If I reformat, I get
<Regenaxer> (de add-word (Trie Word)
<Regenaxer> (ifn Word
<Regenaxer> (cons 'ok Trie)
<Regenaxer> (let Hd (car Word)
<Regenaxer> (ifn (assoc Hd Trie)
<Regenaxer> (cons (list Hd (add-word () (cdr Word)) Trie)
<Regenaxer> (cons (list Hd (add-word (assoc Hd Trie) (cdr Word))) Trie))) ) ) )
<Regenaxer> But I don't know what is needed ;)
<Regenaxer> The second assoc is redundant
<beneroth> T
<beneroth> @ could be used instead
<Regenaxer> (de add-word (Trie Word)
<Regenaxer> (ifn Word
<Regenaxer> (cons 'ok Trie)
<Regenaxer> (let Hd (car Word)
<Regenaxer> (ifn (assoc Hd Trie)
<Regenaxer> (cons (list Hd (add-word () (cdr Word)) Trie)
<Regenaxer> (cons (list Hd (add-word @ (cdr Word))) Trie))) ) ) )
<Regenaxer> yes
<Regenaxer> But it seems wrong
<beneroth> : (add-word () (chop "cat"))
<beneroth> -> ("c" ("a" ("t" (ok))))
<Regenaxer> I'm out, cannot browse the link
<joncfoo> ah thanks
<beneroth> remove the list
<beneroth> (de add-word (Trie Word)
<beneroth> (cons 'ok Trie)
<beneroth> (if (not (assoc hd TRIE))
<beneroth> (ifn Word
<beneroth> (let Hd (car Word)
<beneroth> (cons Hd (add-word NIL (cdr Word)) Trie)
<beneroth> (cons Hd (add-word (assoc Hd Trie) (cdr Word)) Trie) ) ) ) )
<joncfoo> the (list Hd ...) does the trick
<beneroth> joncfoo, that you wanted?
<beneroth> oh okay
<beneroth> notice (cons) may take arbitrary many arguments
<Regenaxer> The code still has one 'hd'
<beneroth> yeah and a TRIE xD
<Regenaxer> and 'TRIE'
<Regenaxer> :)
<beneroth> exercise for the reader :P
<Regenaxer> exactly
<joncfoo> haha
<joncfoo> thanks y'all!
<beneroth> you're welcome
<beneroth> have fun
<Regenaxer> :)
<joncfoo> this is what I ended up with:
<joncfoo> (de add-word (Trie Word)
<joncfoo> (cons 'ok Trie)
<joncfoo> (let Hd (car Word)
<joncfoo> (if (not Word)
<joncfoo> (if (not (assoc Hd Trie))
<joncfoo> (cons Hd (add-word () (cdr Word)) Trie)
<joncfoo> (cons Hd (add-word (assoc Hd Trie) (cdr Word)) Trie)))))
<joncfoo> ? (add-word () (chop "cat"))
<joncfoo> -> ("c" ("a" ("t" (ok))))
<joncfoo> I'll change to ifn soon :P
<Regenaxer> great
<Regenaxer> you can also factor out the 'cons Hd'
<beneroth> T
<Regenaxer> (cons Hd (ifn (assoc ...
<Regenaxer> Nitpicking ;)
<joncfoo> =]
<beneroth> using (ifn) instead of (if) allows you to re-use the result of the condition (stored in @) for the positive case
<beneroth> (assoc Hd Trie) is 3 cells. @ is one cell. 2 cells saved :P
<Regenaxer> right :)
<beneroth> = lower memory usage and quicker execution (less stuff to be shoveled to the CPU)
<beneroth> but yeah, that is the icing on the cake :D
<beneroth> when in doubt, keep it readable over optimized
<Regenaxer> We had such discussion here with aw- a few days ago
<beneroth> though in picolisp optimized is usually more readable, too ^^
<beneroth> yeah?
<beneroth> must have missed it
<Regenaxer> The main point is to avoid function call overhead
<Regenaxer> (ifn X <- (if (not X)
<Regenaxer> 'not' is a tiny function, but the overhead to call it is large
<Regenaxer> We are in an interpreter
<beneroth> aye
<beneroth> the universal recommendation to lower cell count works :)
<beneroth> s/lower/minimize
<Regenaxer> yes, simple rule
<joncfoo> what's the equivalent of reduce/fold in piolisp?
<beneroth> what is reduce/fold doing in clojure? :P
<joncfoo> oh fine I'll write it :P
mtsd has joined #picolisp
<tankf33der> here many clojure's functions
<tankf33der> fold is here:
<beneroth> haha nice
<beneroth> I still have no idea what the purpose is ^^
<tankf33der> afk.
<beneroth> afk too
<joncfoo> oh nice, you defined -> and ->> :)
<beneroth> note that -> is defined in picolisp (it's a standard function used in pilog context)
<beneroth> therefore the local definition with (use -> ...)
<Regenaxer> ret
<Regenaxer> yeah, tankf33der already solved every known problem ;)
orivej has joined #picolisp
mtsd has quit [Quit: mtsd]
rob_w has quit [Quit: Leaving]
<beneroth> T :))
tankf33der_ has joined #picolisp
tankf33der_ has quit [Client Quit]
patrixl has quit [Read error: Connection reset by peer]