IRC channel logs
2025-04-01.log
back to list of logs
<ieure>How do you intern a symbol in Guile? Or do I not need to intern symbols like in CL and similar Lisps? <ieure>ex. I want to programmaically create a Guix service, (service 'thing the-service-type ...) <rlb>ieure: hmm, what do you mean by intern there? (Don't know Guix yet if that's relevant.) <ieure>rlb, Present in obarray and a singleton such that for any (make-symbol "x") all 'x are eq? <ieure>I don't know if Scheme has an obarray. <rlb>That's true for all symbols by default in guile I think. i.e. unless you explicitly create an uninterned symbol, (eq? 'x 'x) is always true. <rlb>Also note that scheme doesn't have a separate function namepsace. <ieure>Yes, I know it's a Lisp-1, that's not relevant here. <rlb>(my common lisp is rusty :) ) <ieure>The docs specifically say that both make-symbol and symbol->string return uninterned symbols, and uninterned symbols can be not eq? <ieure>Guile has procedures to make uninterned symbols, and symbol-interned? to tell if one is interned or not, but no intern procedure. <rlb>make-symbol, yes - but I've rarely called it <rlb> (eq? 'x (string->symbol "x")) <ieure>rlb, You cannot extrapolate the property I seek -- that *all* 'x are eq? -- from one situation where two happen to be. <rlb>I guess more importantly, what are you trying to do, because normally you just use 'foo and it works. <ieure>As I said, I'm programmatically constructing a list of (service 'foo). <rlb>Sure -- if you ask for an uninterned symbol with make-symbol, you'll get one. <ieure>Right. I want an interned one, is the thing. <rlb>OK, so don't use make-symbol? <rlb>iff you have a string as the source <rlb>But the higher level question might be "what's the source"? <ieure>(map (lambda (application) (simple-service (string->symbol (string-append "geoclue-" application)))) applications) <ieure>(simplified, but enough to get the idea across.) <rlb>OK. I don't know what simple-service does, but if it expects a typical symbol, I'd guess you should be fine... <ieure>It probably works, but it piqued my curiousity. <rlb>OK, so I think the answer may be that typically yes, symbols are interned by default in guile/scheme. <ieure>You regularly need interned symbols when writing macros, and Guile has the notion of interned/uninterned, but no way to intern one... so what do y'all do for that? <rlb>But you *can* ask for uninterned symbols via guile make-symbol if you need them for something. <rlb>you normally don't use common-lisp style unhygenic macros. <rlb>and so it's not an issue. <rlb>well, it's different when it is an issue <ieure> -- Scheme Procedure: make-symbol name <ieure> Return a new uninterned symbol with the name NAME. The returned <ieure>make-symbol is more like CL's gensym <rlb>Sure, and it's rarely used in my experience in scheme/guile. <rlb>but other's may have needed it more of course. <rlb>You typically *won't* use it in macros because you'll be using define-syntax where it doesn't figure. <ieure>I don't have my head around Scheme's macro system. <rlb>i.e. macros "know about scoping" in one sense. <rlb>(very grossly speaking) <rlb>There, when you do need to "break hygiene" because you *want* to cause aliasing/shadowing, etc. you use syntax case, and then syntax->datum and datum->syntax to do the same thing more explicitly. <rlb>"syntax-case" I meant. <rlb>In some sense you can think of the hygenic macro expansion code as carrying the scope information along with each symbol, i.e it's not just 'foo you're rewriting it's "foo from here". <ieure>Getting my head around Scheme macros is probably a job for another day, though if you have a link to something that explains it in context of TradLisp macros, I'd love to read that. <rlb> Hmm, not offhand, and I'd start with syntax-rules -- much easier to follow, and roughly all you need until you need to break hygiene. <rlb>and guile has a further simplification for a subset of cases via define-syntax-rule <rlb>There's some description of that in the guile info pages. <rlb>but some of that's more "reference" oriented, though there are examples. <rlb>(if you know clj I might have some define-syntax examples of some of those forms) <ieure>The issue is that reference is only good if I understand the concepts, which, I don't. <rlb>in case it's helpful, and there are some examples, but whether it's still too "reference oriented" for your purposes, I'm not sure. <rlb>e.g. see the "when" definition in there, etc. <ieure>Yeah, not super helpful. Is the first example (define-syntax when) a recursive macro? Or is the (when condition exp ...) calling the existing when? <rlb>It's pattern matching, i.e. the first form is the pattern, and the second is the expansion, and by default ... is special, meaning (roughly) zero or more of what came before. <rlb>and there can be multiple pattern/expansion pairs (a bit like cond) <rlb>Though ... is a bit fancier than it might at first appear. <ieure>Yeah, picked up on that, but wasn't clear to me if the "if" and "when" were two different patterns or pattern/action. <rlb>That's the expansion <ieure>Also not really clear whether ... is actual Scheme syntax or just "put yer code here bub" manual style. <rlb>the "second form" in the pair <rlb>it's fancier it's sort-of "zero or more" of the thing before. <rlb>wrt fancier than you might think: <rlb> ((_ (x y) ...) (list (list x ...) (list y ...))))) <rlb>Then try (foo (1 2) (3 4)) <rlb>Oh and because hygienic, you don't have to worry about the names you pick in the expansions, they will always be distinct from variables in the replacement scope, which is why you don't need gensym, etc. <old>god knows I feel like I caveman when I use the pre-processor or C++ templates after a day of using syntax-case <old>can't believe that we have such technology not available else where <dsmith>I read something somewhere about syntax-rules macros. Often (defmacro type) macros were documented with "this input produces this output" as a kind of input pattern and output template. <dsmith>Why not just use the pattern and template directly when defining the macro <dsmith>SO in one sense, they are self-documenting. <dsmith>The old-style documentation *is* the macro <ArneBab>old: syntax case feels very complex to me, but after seeing how far I could push it in enter-three-witches (the (Enter (name name ...) (name2 name2 ...)) macro creating the macros (name) and (name2) which check whether the full name is used correctly and then quasiquote their body and run it through macros), this brings a power I have never seen anywhere else. <old>I agree that syntax-case does feel intimidating at first, but mastering it is really helpful I found <old>the realy beast is psyntax <old>when you want to implement syntax-case in a new lisp I suppose