IRC channel logs


back to list of logs

<please_help>are (quote (list a b c)) and (list (quote a) (quote b) (quote c)) supposed to be equivalent?
<davexunit>please_help: no
<davexunit>(quote (list a b c)) returns the list '(list a b c)
<please_help>Is (list (quote a) (quote b) (quote c)) supposed to be equivalent to '(a b c)?
<davexunit>they are not eqv?, but they are equal?
<please_help>Does unquoting '(a b c) not give (list 'a 'b 'c)?
<davexunit>`,'(a b c)
<davexunit>(equal? '(a b c) (list 'a 'b 'c))
<davexunit>=> #t
<please_help>(define-syntax uq (syntax-rules (quote) ((_ (quote x)) x)))
<davexunit>I'm extremely confused.
<davexunit>'(a b c) and (list 'a 'b 'c) are lists with the same exact elements
<please_help>(uq '(+ 1 2)) => 3
<please_help>(define-syntax play-it
<please_help>(syntax-rules (quote)
<please_help>((_ (quote x) bindings) (let bindings x))))
<please_help>(play-it '(+ x y) ((x 10) (y 20))) ;=> 30
<davexunit>I don't understand the point of this macro, 'unquote' already has a meaning
<davexunit>what you're doing is a simple 'eval'
<please_help>unquote doesn't exist outside quasiquote forms, this macro does
<davexunit>(eval '(+ 1 2) (current-module))
<please_help>yes it is
<davexunit>so you should use eval
<please_help>but play-it is more like local-eval
<please_help>e.g. (let ((x 10) (y 20)) (eval '(+ x y) (current-module))) wouldn't work
<davexunit>no, but your macro doesn't work
<please_help>and that's where the unquote macro is useful, but the core of the question remains: somehow I don't successfully generate the '(list expr) to make use of it from parsing the original expr
<please_help>it does
<davexunit>since it's a macro, it's expanded at compile time
<please_help>try it yourself
<please_help>the play-it macro that is, of course
<davexunit>there's no reason to use 'uq', you can just remove the quoting
<please_help>you can't remove the quoting when the form is already quoted unless you're in a quasiquote context.
<davexunit>you're not understanding.
<davexunit>your macro is moot.
<davexunit>you wrote a macro that transforms (quote foo) into foo
<please_help>I just realized it doesn't work in the context I want it to, which is (define obj '(+ 1 2)) (uq obj)
<davexunit>treat it like simplification in math, (uq '(foo)) can simply be rewritten as foo
<davexunit>nothing is accomplished with uq
***_zxq9_ is now known as zxq9
<jmd>Can anyone say what's wrong with
<taylanub>jmd: you're putting symbols into that alist, not the procedure objects
<taylanub>in Scheme, once you have a symbol object (by using `quote' or `string->symbol'), you won't be able to use it like a variable anymore
<taylanub>jmd: the correct version would be i.e. define the procedures first, and put them in the alist by using `unquote' (the comma). you can see what's in the alist by displaying it; you will note that it contains #<procedure> objects and not symbols.
<jmd>taylanub: Thanks
<Zerock>Anyone know why mcron claims it can't see files in my .cron directory even though it was able to compile them?
***h_ll_k_n is now known as hellekin
<please_help>The only way to do anything useful with syntax objects is within a syntax-case?
<taylanub>please_help: at compile-time, you could say. though there might perhaps be uses of them at run-time as well, like for dynamic code generation or so, I don't know
<please_help>It seems possible to generate syntax objects at runtime based on other syntax objects with some restrictions, however it doesn't seem to be possible to do anything with them afterward.
<please_help>I might be missing something of course
<please_help>especially, it seems that the syntax object has to be passed around and processed immediately and may not be stored or built upon.
<taylanub>scheme@(guile-user)> (let ((plus (syntax +)))
<taylanub> (eval `(,plus 2 3) (scheme-report-environment 5)))
<taylanub>$5 = 5
<taylanub>please_help: you can insert a syntax object in a sexpr to be evaluated, and the syntax object will carry over its lexical information
<please_help>but you can't append eval-time bindings without resorting to local-eval, right?
<taylanub>hm, actually that doesn't seem very useful; if it's really a lexically bound variable, then its binding will not be present during the evaluation:
<taylanub>it could serve like `gensym' but we have `generate-temporaries' for that
<taylanub> here it's used like gensym
<please_help>More like, (define s #'(+ x y)) (let ((x 1) (y 2)) (eval s (some-environment)))
<taylanub>well the code passed to eval will not be able to access the eval call's lexical environment anyway
<please_help>unless there was a way to add the bindings to the environment passed to eval, for example
<taylanub>i.e. (let ((x 0)) (eval 'x some-env)) will raise an unbound variable error (unless `some-env' has a binding for x)
<taylanub>in Guile, environments and modules are the same thing, so you could programmatically add bindings to an environment via module-add! or so, see (info "(guile) Module System Reflection")
<taylanub>it seems one can also just eval a definition in an env: by the way, regarding all this syntax object stuff, and evaling definitions, I don't know how committed Guile is to keeping these features (since they are rather obscure, and not in any standard)
<jmd>I believe there is a function which does the equivalent of (if (x) (x) y) - but I can't remember what it is called.
<taylanub>(well, being able to eval definitions is not so obscure I guess)
<taylanub>jmd: do you mean (if x x y)? (your code would call 'x' twice)
<please_help>he probably means "aif"
<taylanub>the shorthand for (if x x y) would be (or x y), when x should be evaluated once
<jmd> Unbound variable: aif
<jmd>taylanub: Well perhaps I should have written (let ((z (x))) (if z z y))
<taylanub>aif is anaphoric if, it lets you do stuff like (aif (blah) (frob it)) where 'it' will be bound to the result of (blah). it's often discouraged in Scheme because it implicitly binds 'it'
<taylanub>jmd: indeed. 'or' can do that. your example also makes me think of and=>, and of SRFI-2 / and-let*...
<jmd>yes I think and=> was what I wanted.
<please_help>is there a way to make a copy of an environment so as not to polute it?
<jmd>please_help: If you find such a way then we will no longer have to worry about global warming.
<taylanub>please_help: there are some undocumented procedures for modules I think; there might not be a direct copy procedure but it should be possible to implement one by iterating over all bindings in a module and adding them to another
<please_help>sounds very slow
<please_help>maybe save-module-excursion
<taylanub>it should not be an operation you have to do very often?
<taylanub>save-module-excursion just saves and restores what module you're in AFAIK
<please_help>(lambda ()
<please_help>(module-define! (current-module) 'x 10)
<please_help>(module-define! (current-module) 'y 20)
<please_help>(eval s (current-module))))
<please_help>unfortunately that doesn't seem to work right, the bindings don't get restored at the end and the wrong bindings are used inside.
<taylanub>you're reading the documentation wrong :) it will just prevent any module *changes* (not mutations) within the thunk from affecting the outside of the thunk.
<taylanub>e.g. (save-module-excursion (lambda () (set-current-module foo)))
<please_help>how lame
<ijp>make a fresh module, import whatever you need
<please_help>I'll have to make a fresh module, import every symbol in current-module, and then add a few bindings to that potentially "often" (whatever that'll mean).
<please_help>actually I know what that'll mean: somewhere between 6 and 20 times per iteration where I can expect ~100k iterations
<please_help>is clearing a hash-table relatively quick?
<please_help>alternatively, is creating a new hash-table relatively quick?
<jmd>Is there a shortcut for (and x (not (null? x)))
<ijp>I don't think so
<Zerock>jmd: You could easily make one. (define (ready? x) (and x (not (null? x))))
<ijp>that went without saying
<taylanub>you could be naughty and use Elisp's not/null :P
<bipt>which is available in scheme as 'nil?': (map nil? '(#nil #f ())) => (#t #t #t)
<taylanub>ah, I forgot about that
<taylanub>I guess one should really not abuse that for such a situation though
<taylanub>wait, I have no nil? in (guile-user)
<bipt>hm, maybe it's just in 2.2
<please_help>is there no way to set the field-printer of an srfi-9 record separately from the entire type-printer e.g. as part of (srfi srfi-9 gnu)?