philip.mcgrath
2019-8-14 10:27:12

Just for fun, here’s an example with lex/yacc-style parsing: #lang racket (require parser-tools/lex (prefix-in : parser-tools/lex-sre) parser-tools/yacc) (module+ test (require rackunit)) (define-empty-tokens delim-tokens (open close eof)) (define-tokens atom-tokens (int)) (define lex (lexer [(:+ whitespace) (lex input-port)] [(:+ numeric) (token-int (string->number lexeme))] [#\( (token-open)] [#\) (token-close)])) (define parse (parser [tokens delim-tokens atom-tokens] [start Element] [end eof] [error (λ (tok-ok? name val) (error "parse error"))] [grammar (Element [(int) $1] [(open Element* close) $2]) (Element* [() '()] [(Element Element*) (cons $1 $2)])])) (define (lex+parse-string str) (define in (open-input-string str)) (parse (λ () (lex in)))) (module+ test (check-equal? (lex+parse-string "(1 2 (3 4 (5 6)) 7)") '(1 2 (3 4 (5 6)) 7)))


samth
2019-8-14 15:09:15

badkins
2019-8-14 15:14:05

Awesome - thanks!


sydney.lambda
2019-8-14 23:31:40

@philip.mcgrath thanks for the example :) Does the first rule for Element* match if there are no elements left, so as to “complete” a list in a way similar to: (if (null? ls) '() ;recur) ?


badkins
2019-8-15 00:20:41
#lang racket

(module A racket
  ...)

(module B racket
  (require 'A)
  ...)

; ==> require: unknown module module name: #<resolved-module-path:'A>

I’ve tried a few different variations such as (module* B #f etc. to no avail.


badkins
2019-8-15 00:21:43

Of course, I’d also want to `(require ’B) at the top level to use it.


badkins
2019-8-15 00:27:06

“A submodule declared with module can import any preceding submodule declared with module.” Searching for import in the docs came up with odd results.


notjack
2019-8-15 00:33:00

@badkins “import” = require, and you need to do (require (submod ".." 'A)) I think


badkins
2019-8-15 00:35:05

@notjack thanks, you were close :slightly_smiling_face: (require (submod ".." A)) apparently no need to quote in this case, where I do need to quote (require 'B) for some reason


notjack
2019-8-15 00:35:30

…weird


badkins
2019-8-15 00:35:42

I guess the ".." makes sense like going up a directory then back down


notjack
2019-8-15 00:41:32

This is the kind of thing that makes me wish module names were just URLs so I could reuse my knowledge of relative url syntax instead of learning the strange racket-specific notation


philip.mcgrath
2019-8-15 06:32:43

Yes, that’s right.