Hacker News new | past | comments | ask | show | jobs | submit login

Any reason for the fugly #: syntax? That's mandated by Guile?



They're keyword arguments, I suspect the #: prefix was chose precisely because it is ugly so it'll almost never conflict with a name a programmer might actually want to give as an argument, Racket uses it too. http://docs.racket-lang.org/guide/keywords.html


The # is extensible reader syntax. You can install your own readers for characters following the #. #\ is for the character reader, #: for keywords, etc.

Guix uses #~ for G-expressions, for example.


Thanks for providing the link to the documentation in Racket. For people like me who don't know how to program in Scheme, this quote from the documentation might make it click (it is at the end of the page):

Despite their similarities, keywords are used in a different way than identifiers or symbols. Keywords are intended for use (unquoted) as special markers in argument lists and in certain syntactic forms. For run-time flags and enumerations, use symbols instead of keywords. The example below illustrates the distinct roles of keywords and symbols.

Examples:

    > (define dir (find-system-path 'temp-dir)) ; not '#:temp-dir
    > (with-output-to-file (build-path dir "stuff.txt")
        (lambda () (printf "example\n"))
        ; optional #:mode argument can be 'text or 'binary
        #:mode 'text
        ; optional #:exists argument can be 'replace, 'truncate, ...
        #:exists 'replace)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: