IRC channel logs

2019-10-16.log

back to list of logs

<chrislck>jcowan: recurse on rest argument means what?
<chrislck>daviid: install MSYS2 gives you guile on windows
<daviid>chrislck: a very old version i think, so i'll wait spk121 patch and instructions to grab 2.2.6, tx
<chrislck>true
<chrislck>gnucash guile is 2.2 at least
<jcowan>chrislck: Something like this: (define (a . b) (apply f (cons a (car b) (cdr b)))
<jcowan>so a is the first argument and b is a list of the rest, and then we call a function f giving it the first two arguments and the remaining arguments.
<jcowan>try that again
<jcowan>(define f (a . b) (if null? b) a (apply f (g a (car b) (cdr b))))
<jcowan>the trouble is that with f's signature, the list (cdr b) will be copied before calling f recursively. Which makes an O(n) function into O(n^2)
<joshuaBPMan>wingo: Hey Andy! Thanks for making guile bro! I've pretty much spent the entire day hacking away at a very simple website. guile is super fun to make websites in as it turns out!
<joshuaBPMan>jcowan: what does it mean to have a function like (define (a . b) ...)
<joshuaBPMan>I've seen (define (a b) ...) But what is (a . b)?
<jcowan>joshuaBPMan: It binds the first argument to a and a list of any other arguments to b. It's how Scheme does procedures with a variable number of arguments.
<jcowan>(define (foo a b) means that foo has exactly 2 arguments.
<jcowan>whereas (a . b) means it has one or more, (a b . c) means 2 or more, etc.
<nisstyre>jcowan: I always found that syntax confusing because it looks like a dotted pair
<nisstyre>maybe that was intentional
<jcowan>It is a dotted pair
<nisstyre>or is it actually a dotted pair?
<nisstyre>ok yeah
<jcowan>Lambda binding is a crude form of pattern matching: (a b c) is matched against the actual arguments, say (1 2 3).
<nisstyre>they could've done something like (define (foo a (rest args)) ...) at the expense of more typing
<jcowan>But not as neatly!
<jcowan>Matching the pair (a . b) against (1 2 3) naturally matches a with 1 and b with (2 3)
<nisstyre>true
<jcowan>As a degenerate case, (lambda x ...) would match x against (1 2 3)
<jcowan>a non-pair can be seen as an improper list.
<nisstyre>I'm only familiar with pattern matching in Racket and it works somewhat differently there
<nisstyre>actually no, it's the same
<nisstyre>nvm
<jcowan>the car of the formal arg list is bound to the car of the actual arg list, and then recurse on the cdr. When you get to the end ...
<nisstyre>I always do (match foo [(list-rest a bs) ... ]) though
<nisstyre>which is more verbose
<jcowan>you either have () in both, or () in just one (wrong number of argments) or a symbol in the formal args and a list in the actual args.
<jcowan>so they are bound together
<jcowan>In pre-CL meta-circular interpreters this is called "evlis"; it takes the lambda list and the cdr of the actual call (so each eleemnt of the latter has to be evaluated in the current context)
***malaclyps2 is now known as malaclyps
<spk121>joshuaBPMan: define (a . b) means that b holds any remaining arguments. So (a . b) means that the 1st arg is a and then 2nd through nth arg is in b
*chrislck enjoys lispy discussions
<chrislck>in other news, gnucash guile code is now much less ugly, and has some good algos https://github.com/Gnucash/gnucash/blob/maint/libgnucash/scm/utilities.scm
<roptat>how to find elements in common between two lists?
<roptat>like (in-common '(2 3 5 7 11) '(1 3 5 7 9)) -> '(3 5 7)
<roptat>is there an existing function for that, or should I create one myself?
<chrislck>roptat: srfi-1's lset-intersection
<roptat>wow, thanks :)
<chrislck>jcowan: thx for pointers on recursing on rest arguments, very useful. perhaps these pearls belong somewhere in documentation.
<jcowan>chrislck: It's easy to solve, fortunately: (define foo (a . b) (foo* a b)), where foo* does the actual recursive work. Because its second argument is a list, it is passed around as-is rather than being re-created for each recursion.
<apteryx>mmh, why doesn't this shell snippet do what I'd expect?: export TEST=something; guile -c '(getenv "TEST")'
<apteryx>mainly, TEST is not defined in the Guile child process
<apteryx>ah, silly me, I need to pk it ;-)
<apteryx>nevermind :-)
<amz3>I disagree with richard stallman behavior. I hope GNU project is not too much tainted with RMS bizar (!) positions. I wish you good luck!
<amz3>sneek: later tell joshuaBPMan regarding mime-type: https://github.com/a-guile-mind/guile-web/blob/master/src/web/mime-types.scm. there is database in /etc/mime.types that you might want to rely on.
<sneek>Got it.
<amz3>sneek: later tell joshuaBPMan I basically gave up on the web because of this https://www.owasp.org/index.php/Cross-Site_Request_Forgery_(CSRF). It has been updated, tho. Unlikely to be a better story. My understanding was that one could not have a secure, useable and dynamic web application without running wasm or javascript.
<sneek>Got it.
<amz3>sneek: later tell joshuaBPMan I mean you can not even have forms without lots of trickery
<sneek>Will do.
<stis>hello guilers!
<weinholt>hej stis