IRC channel logs

2015-04-29.log

back to list of logs

<please_help>I want to pass either the element, or the quoted element, to a function that assembles part into an evaluable expression
<please_help>(list? (quote (a . b))) ;=> #f
<please_help>that's good for me
<saul>Why is that good?
<please_help>so really my real question should be: (list? (quote x)) iff x is a function application? I think.
<saul>(list? (quote (1 2)) ; is not a function application
<please_help>saul, it is good because I want to dispatch based on whether an expression is a quoted function application or not. That is because a quoted, quoted function application is a list of symbols and thus needs 2 passes of eval to correctly (in my case) resolve to the function application.
<please_help>The form (a b ...) is called function call, or procedure application or (perhaps this is abuse) function application. It doesn't matter whether a is actually bound to a procedure.
<saul>How do distinguish whether it is just a list of symbols? e.g., (quote (+ - * /))
*saul is not trying to be difficult, he just wants to understand the goal better.
<dsmith-work>please_help: Right. Doesn't need to be a symbol, just needs to evaluate to a function ((if #t + *) 3 4)
<please_help>dsmith-work: for it to be valid, but it's still a (even though invalid) function application if it doesn't evaluate to a function, right?
<dsmith-work>A function application has to have something that evaluates to a fuction in the car of the list.
<dsmith-work>Could be a lambda expression, for example.
<saul>Unless its car is a special form (quote, begin, if|cond), a parenthetical Scheme object is presumed to be a function application.
<dsmith-work>scheme@(guile-user)> (((lambda () +)) 1 2)
<dsmith-work>$1 = 3
<dsmith-work>scheme@(guile-user)> ((lambda (a b) (+ a b)) 1 2)
<dsmith-work>$2 = 3
<please_help>(1 2) => ERROR: In procedure 1:
<please_help>ERROR: Wrong type to apply: 1
<please_help>so it's still a procedure application.
<saul>please_help, yes.
<please_help>yes, a list of symbol breaks the test
<please_help>the problem I'm trying to solve is composing functions from either functions or lists into an evaluable form
<please_help>the point being to inject additional information before the final evaluation
<saul>TMK, the only way to distinguish between a list and function application is whether it is quoted.
<saul>* a list of data elements
<saul>All unquoted lists that are evaluated are either special forms or function applications.
<dsmith-work>or errors
<dsmith-work>please_help: So what do you mean by "additional information" ?)
<please_help> http://paste.lisp.org/+35WK
<please_help>this macro almost does what I need it to.
<please_help>The extra info in this case is local bindings. The use case is partial bindings for future evaluation. I think wrapping in (lambda ...) forms don't work because the expression will actually come from a processed structure and thus be in list form.
<please_help>This avoids doing local-eval.
<please_help>(define def1 (expr-bind (+ x y) ((x 10))))
<please_help>(define def2 (expr-bind def1 ((y 20))))
<please_help>(display (eval def2 (current-module))) ;=> 30 (OK)
<please_help>(display (eval (expr-bind def1 ((y 20))) (current-module))) ;=> 30 (also OK)
<please_help>(display (eval (expr-bind (expr-bind (+ x y) ((x 10))) ((y 20))) (current-module))) ;=> (let ((x 10)) (+ x y)) (not OK)
<please_help>basically, I want to expand all macros before this macro processes the result.
<dsmith-work>Ahh
<please_help>is it possible to pattern-match against macro expressions?
<dsmith-work>please_help: You can do other matches internally on subexpression. I'm not a expert enough to know, but I've seen it done.
<dsmith-work>please_help: Also, there are matchers that are not macros.
<dsmith-work>please_help: And you might not need to eval. Maybe apply work work better. Build up your list of args and apply some function to them.
<dsmith-work>s/work work/would work/
<please_help>there's e.g. ((_ a b (quote c ...) ...)) which would match if the 3rd expression is quoted, assuming quote is in the lexical list, and there's (ice-9 match) for out-of-macro matching I guess
<dsmith-work>Ya, (ice-9 match)
<please_help>how does "macro?" even work? It seemingly can't be used as (macro? macro-name) (source expression failed to match...)
<please_help>I would still need to eval even if I were to use apply since '(+ x y) would become (apply (eval '+ (...)) (list x y))
<dsmith-work>True. But do you need to quote + ?
<dsmith-work>Or is that the point.
<please_help>Both. I'll only ever know about + by parsing a compute graph that resolve to a syntax object (which needs to be eval'd just like a quoted + would), and the parsing of the graph returning an expression that can be manipulated is the point.
<mark_weaver>please_help: if you want to have the subexpressions macro-expanded before the outer macro sees it, your best bet is to use 'ck'. See http://okmij.org/ftp/Scheme/macros.html#ck-macros
<mark_weaver>recent versions of guile include 'ck', in the (system base ck) module
*mark_weaver goes afk
<please_help>thanks for the ref
<please_help>current version, using ck macros: http://paste.lisp.org/+35WK/1
<please_help>I don't know how robust it is against (list 'quote ...) inputs though
<please_help>next step, figuring out how to autoquote components correctly before entering the ck macro.
<nalaginrut>morning guilers~
***michel_mno_afk is now known as michel_mno
<nalaginrut>do we have define-once for macros? say, define-syntax-once ?
<please_help>actually this doesn't seem to work, (define first (ck () (%expr-bind-ck '(+ x y) '((x 10))))) (define second (ck () (%expr-bind-ck first '((y 20)))))
<please_help>source expression failed to match any pattern in form (ck (((%expr-bind-ck) (quote ((y 20))))) first)
<please_help>It also fails for (ck () (%expr-bind-ck (ck () (%expr-bind-ck '(+ x y) '((x 10)))) '((y 20)))) which would be the correct resolution of the user-side macro
<ArneBab>God uses #Lisp https://farm3.staticflickr.com/2876/10212337584_96a80e6049_o_d.jpg flickr.com/photos/wikkit/10212337584/ #cc by-sa by @wikkit ☺
<ArneBab>^ I hope it makes you smile, too ☺
<nalaginrut>nice~
<phant0mas>hey guys I have a question, I am running guile using ./pre-inst-env guile with the script exporting GUILE_LOAD_PATH and GUILE_LOAD_COMPILED_PATH
<phant0mas>any suggestion on how to do the same through geiser in emacs?
<davexunit>can someone on a gnu/linux system run this and tell me if it crashes for them?
<davexunit>unshare --pid guile
<davexunit>I get this backtrace: http://paste.lisp.org/display/147639
<taylanub>does `match' somehow support optional elements in lists? I have a list that's either length 2 or 3, and I'd like to destructure it with a default value for the third element.
<davexunit>taylanub: you wouldn't be able to bind an identifier for the missing third element in the case of a 2 element list
<taylanub>guess I'll have to do ((foo bar rest ...) (let ((rest (if (null? rest) default (car rest)))) ...))
<davexunit>you might as well not use the pattern matcher
<davexunit>make 2 cases
<davexunit>one to match a 2 element list and one to match a 3 element list
<taylanub>will need to join those branches again somehow, it's cumbersome either way
<davexunit>I don't see how
<davexunit>abstract the commonalities to a procedure
<taylanub>it's awkward using an internal define (or equivalent) just for that reason...
<taylanub>went with the (foo bar . rest) pattern; the handling of the rest-list introduces one fairly obvious line of code so it should be fine
<davexunit>but if you're car/cdring you might as well not be using match.
<taylanub>it's just one null?/car
<davexunit>which you should be using match for
<taylanub>for which there's no clean way :D
<davexunit>I told you the clean way but you don't want to use it.
<davexunit>you have 2 cases and match will account for them.
<taylanub>I disagree that it's clean because it forces me to factor out a piece of code which doesn't make sense outside its context
<dsmith-work>sneek: later tell phant0mas You could write a simple shell script that sets those env values and then execs guile. Point geiser at that script.
<sneek>Got it.
<dsmith-work>sneek: botsnack
<sneek>:)
<dsmith-work>!uptime
<sneek> 14:20:07 up 30 days, 5:29, 0 users, load average: 0.00, 0.01, 0.05
<alezost>sneek: I believe ph4nt0mas and phant0mas is the same person. What do you think?
<sneek>Got it.
<dsmith-work>ArneBab: Is that you? (ph4nt0mas and phant0mas)
<ArneBab>no
<dsmith-work>ok
<Sleep_Walker>phantomas wouldn't reveal his identity so easily
<davexunit>'unshare --fork --pid guile'
<davexunit>guile as PID 1 (in a namespace) :)
<dsmith-work>What's a namespace?
<davexunit>a kernel namespace. a way of creating isolated groups for global resources (network, processes, mount points, etc)
<dsmith-work>Is that anything like a fbsd jail?
<davexunit>similar, yeah.
<dsmith-work>New? (I've not heard of it before)
<davexunit>the latest namespace, the user namespace, arrived in 3.8
<dsmith-work>ok
<dsmith-work>New to me. I've been running 3.2
<davexunit>oh.
<davexunit>that's quite old now.
<dsmith-work>Hmm. Very interesting...
<dsmith-work>Hmm. Unshare was added almost exactly 10 years ago.
<dsmith-work> http://lwn.net/Articles/135266/
<davexunit>unshare has been around awhile
<davexunit>but all of the namespaces that clone/unshare are capable of operating on are somewhat new
<ArneBab>Sleep_Walker: ☺
<stis>taylanub: you can use (apply (lambda* (x y #:optional (o 1)) ...) listval)
<stis>if you don't want to dig deeper into the lists
<stis>also it's quite easy to do a macro for a recursive case-lambda and use it like
<stis>(case-lambda-rec lp ((x y) (lp x y 1)) ((x y o) ...))
<stis>you may also use = in match with f = (lambda (x) (if (pair? x) (car x) 1))
<stis>(match x ((a b . (= f o)) ...)
***michel_mno is now known as michel_mno_afk
<stis>or for the fun of it, (define (f2 n op) (lambda (x) (if (>= (length x) n) (list-ref x n) op))
<stis>and use it as (match x ((a b . (= (f2 0 1) o)) ...))
<stis>err, replace >= with > in the f2
<stis>combine '=' with 'and' and you can take out more of the optional values
<ijp>stis: (a b . (= f o)) looks like it shouldn't work
<ijp>since that is the same as (a b = f o)
<taylanub>I also wish patterns like (pre ... foo post ...) worked, regardless of order.
<taylanub>(don't remember the exact use-cases, but I remember having wished for it several times...)
<phant0mas>haha dsmith-work alezost phant0mas and ph4nt0mas are both the same
<phant0mas>I have two workstation sitting around logged in the irc :P
<sneek>Welcome back phant0mas, you have 1 message.
<sneek>phant0mas, dsmith-work says: You could write a simple shell script that sets those env values and then execs guile. Point geiser at that script.
<phant0mas>now there is another phantomas at #coreboot, but he is not me
<phant0mas>and dsmith-work thanks for the answer :-)
<ijp>taylanub: and when foo appears twice?
<taylanub>ijp: in my case the point is to do it recursively to go through all foo, until it doesn't match anymore
<ArneBab>why does guild select the language with --from=LANG and guile with --language=LANG?
<stis>taylanub: that pattern is not uniquely defined, you need to add that it should be greedy or vice verse, (,aybe you did then thats my bad)
<taylanub>stis: it would be enough if it worked like the * regexp operator, i.e. both "..." are greedy so the fisrt one chomps any additional 'foo' from the front (so one would be processing foos right to left, but that's fine)
<ijp>ArneBab: guild needs to distinguish two languages, not just one
<ijp>the one you are inputting, and the one you are outputting
<ArneBab>ijp: yes - I just wonder why the --from isn’t available as --language, too
<taylanub>a --language alias for --from wouldn't be bad perhaps
<ArneBab>ijp: one we can say `guild --from=ecmascript --to=asm.js` ☺
<ArneBab>require("srfi.srfi-1").iota(10, 5, 7); # ftagn
<ArneBab>sorry, #fhtagn
<ArneBab>sneek: later tell wingo: There I added a footnote to the book just to get lost in the blog post I linked to ☺ (guess which one ☺)
<sneek>Okay.
<ArneBab>sneek: later tell wingo: require("srfi.srfi-1").iota(10, 5, 7); # fhtagn
<sneek>Okay.
<davexunit>encoding module names as strings :(
<ArneBab>things I still stumble over: (use-modules (statprof))(with-statprof #:loop 1000000 (define a 1))
<ArneBab>unknown location: no expressions in body in form (lambda () (define a 1))
<ArneBab>I always find it surprising to see context-specific limitations like this - at was also a strange experience in Fortran (where all declarations have to be done before any functional part of subroutines)
<please_help>I read about "macro-lambdas" in r5rs (i.e. ??!lambda) and other such constructs (i.e. ??!apply, and ??!), but I can't find any reference to those (maybe I don't know the term for them, and of course search engines don't like symbols). Where can I read about that?
<dsmith-work>please_help: ??! doesn't appear in doc/r5rs/r5rs.texi
<dsmith-work>please_help: You sure it was r5rs?