abmclin
2017-12-6 14:43:15

I’m far from a macro expert (yet) but I don’t see why it’d be difficult to write a macro to do what you want. In spite of superficial similarities, ’(a b c) and (list a b c) are two different things and have different shapes. ’(a b c) is really (quote (a b c)). At the minimum it should be a quite simple matter of having your macro match on the two different shapes and process ’(a b c) into “a b c” using standard string functions and return (list a b c) as a list.


ryanc
2017-12-6 15:09:58

@samth @mflatt that test is meant to check that (for “well-behaved” connection types), long-running queries don’t block the execution of other racket threads. I don’t know a good way to test that directly, so it’s written using heuristics that Seemed To Work At The Time.


dedbox
2017-12-6 17:30:24

@me1 @abmclin With the default reader, '(a b c) equals (quote (a b c)) equals (list 'a 'b 'c). I’m not sure you can tell the difference in a regular macro.


dedbox
2017-12-6 17:36:55

Hey, it works.


lexi.lambda
2017-12-6 17:37:41

@dedbox that isn’t true. '(a b c) does read as (quote (a b c)), but expansion stops at quote.


dedbox
2017-12-6 17:39:46

@lexi.lambda so in (quote (a b c)), the (a b c) part is an unexpanded list?


lexi.lambda
2017-12-6 17:44:00

@dedbox I don’t know what you mean by “unexpanded list”. consider reading this https://stackoverflow.com/a/34984553/465378


dedbox
2017-12-6 17:45:35

@lexi.lambda just trying to figure out what we’re calling things. Still not sure how my original statement isn’t true.


lexi.lambda
2017-12-6 17:54:45

well, macros operate on syntax. so while '(a b c) does indeed become (quote (a b c)) at the reader level, it’s quite distinct from (list (quote a) (quote b) (quote c)) at the syntax level, which is the level macros operate at.


lexi.lambda
2017-12-6 17:59:43

you could write: #lang racket (require (for-syntax racket) syntax/parse/define) (define-syntax-parser mac #:literals [quote] [(_ '(id:id ...)) #`(quote #,(datum->syntax #f (string-append* (map (compose1 symbol->string syntax-e) (attribute id)))))] [(_ other:expr) #'other])


dedbox
2017-12-6 18:01:41

ohh.. ok, I was confused about the ordering.


dedbox
2017-12-6 18:03:02

thanks!


lexi.lambda
2017-12-6 18:05:01

mhmm. the order of evaluation is read -> macroexpand -> compile -> runtime eval. '(a b c) and (list 'a 'b 'c) do indeed evaluate to the same thing at runtime, but they are distinct expressions, so prior phases can distinguish them.


dedbox
2017-12-6 18:08:19

I tried this: racket@foo.rkt> (define-syntax f (syntax-rules (list quote) [(f '(a b c)) "tick"] [(f (quote (a b c))) "quote"] [(f (list a b c)) "list"])) racket@foo.rkt> (f '(a b c)) "tick" racket@foo.rkt> (f (quote (a b c))) "tick" racket@foo.rkt> (f (list 'a 'b 'c)) "list"


dedbox
2017-12-6 18:09:56

and this: racket@foo.rkt> (and (equal? '(a b c) (list 'a 'b 'c)) (equal? '(a b c) (quote (a b c)))) #t


lexi.lambda
2017-12-6 18:10:49

yes, equal? compares the expressions after evaluation (since it is just a regular function).


lexi.lambda
2017-12-6 18:12:11

the 'x -> (quote x) translation happens in the reader, which is before macroexpansion, so those two are indistinguishable to macros.


dedbox
2017-12-6 18:12:23

just about to ask that


lexi.lambda
2017-12-6 18:14:17

there are infinitely many distinct expressions that produce '(a b c) when evaluated, so macros can’t detect (without evaluation) “an expression that evaluates to '(a b c)”, since that would solve the halting problem. they can only make decisions based on the syntactic structure of their subforms.


me1
2017-12-6 18:51:43

<3Lisp


me1
2017-12-7 05:23:48

is it possible to write a macro so that ([function name] a b c) becomes (function-name a b c) ?


lexi.lambda
2017-12-7 05:36:38

yes #lang racket (require (for-syntax racket syntax/parse/class/paren-shape) syntax/parse/define (prefix-in r: racket)) (define-syntax-parser #%app [[~brackets _ i:id ...+] (datum-&gt;syntax (first (attribute i)) (string-&gt;symbol (string-join (map (compose1 symbol-&gt;string syntax-e) (attribute i)) "-")))] [(_ other ...) #'(r:#%app other ...)]) but I wouldn’t recommend it.