anything
2021-4-23 10:57:45

Yes, there are so many weird variants of CSV that makes life difficult. Okay, thanks! It looks like df-select with #:filter is what I need.


cb1465
2021-4-23 13:47:51

@cb1465 has joined the channel


chansey97
2021-4-23 19:31:08

Does Racket have identifier-syntax? For example: (let () (define-syntax a (identifier-syntax car)) (list (a '(1 2 3)) a)) ; identifier-syntax: undefined; ; cannot reference an identifier before its definition In the book <https://www.scheme.com/tspl4/syntax.html#./syntax:h3|The Scheme Programming Language>, it says that we can define identifier-syntax in terms of make-variable-transformer. I tried it, but seems doesn’t work? (define-syntax identifier-syntax (lambda (x) (syntax-case x (set!) [(_ e) #'(lambda (x) (syntax-case x () [id (identifier? #'id) #'e] [(_ x (... ...)) #'(e x (... ...))]))] [(_ (id exp1) ((set! var val) exp2)) (and (identifier? #'id) (identifier? #'var)) #'(make-variable-transformer (lambda (x) (syntax-case x (set!) [(set! var val) #'exp2] [(id x (... ...)) #'(exp1 x (... ...))] [id (identifier? #'id) #'exp1])))]))) (let () (define-syntax a (identifier-syntax car)) (list (a '(1 2 3)) a)) ; identifier-syntax: undefined; ; cannot reference an identifier before its definition


soegaard2
2021-4-23 19:35:04

@chansey97 I believe, make-rename-transformer provides the same functionality.


soegaard2
2021-4-23 19:36:12

However, you in your example, (identifier-syntax car) occurs at compile-compile-time, so


soegaard2
2021-4-23 19:36:40

Maybe you just need to wrap your definition of identifier-syntax in begin-for-syntax ?


chansey97
2021-4-23 19:39:44

make-rename-transformaer can work. Thanks. (let () (define-syntax a (make-rename-transformer #'car)) (list (a '(1 2 3)) a))


chansey97
2021-4-23 19:44:31

I just copy-pasted identifier-syntax from the book and noticed that if I comment out the last expression i.e. (let () ...), Racket does not report an error. So I think the definition of identifier-syntax ought to be correct (?) in Racket. But I don’t understand why it reports identifier-syntax: undefined .


soegaard2
2021-4-23 19:46:19

#lang racket (begin-for-syntax (require (for-syntax racket/base)) (define-syntax identifier-syntax (lambda (x) (syntax-case x (set!) [(_ e) #'(lambda (x) (syntax-case x () [id (identifier? #'id) #'e] [(_ x (... ...)) #'(e x (... ...))]))] [(_ (id exp1) ((set! var val) exp2)) (and (identifier? #'id) (identifier? #'var)) #'(make-variable-transformer (lambda (x) (syntax-case x (set!) [(set! var val) #'exp2] [(id x (... ...)) #'(exp1 x (... ...))] [id (identifier? #'id) #'exp1])))])))) (let () (define-syntax a (identifier-syntax car)) (list (a '(1 2 3)) a))


soegaard2
2021-4-23 19:46:52

The problem is that (define-syntax identifier-syntax ...) defines identifier-syntax at phase 1.


soegaard2
2021-4-23 19:47:06

In (define-syntax a (identifier-syntax car)) it is used at phase 2.


soegaard2
2021-4-23 19:47:22

This gives the unknown identifier error.


chansey97
2021-4-23 19:49:47

Very thanks! @soegaard2 Scheme seems no this problem (I tried in Chez), both in REPL.


soegaard2
2021-4-23 19:52:02

The phases work slightly different. If you are interested in the motivation behind Racket’s system, read Flatt’s paper: http://www.cs.utah.edu/plt/publications/macromod.pdf


chansey97
2021-4-23 19:52:43

Thanks!



chansey97
2021-4-23 21:23:18

Add: The Racket equivalent of Scheme identifier-syntax ought to be make-set!-transformer and make-rename-transformer.