Here is a snippet of code in the language: 

#lang network-flow

;; sample graph

problem: maximize from a to d 

node a -- 10 --> b
node a -- 20 --> c
node b -- 30 --> d
node c -- 30 --> d

Here is a link to the language 

http://www.ccs.neu.edu/home/matthias/4620-s18/network-syn-lang.rkt 
<http://www.ccs.neu.edu/home/matthias/4620-s18/network-syn-lang.rkt>

(The github repo for the course is private. Sorry)

— Matthias



> On Feb 15, 2018, at 1:26 AM, Sorawee Porncharoenwase 
> <sorawee_porncharoenw...@brown.edu> wrote:
> 
> Thank you for your advice!
> 
> If your code is online and you don't mind, could you point me to the project 
> or any other tutorial so that I can see the sample code? Right now I have 
> https://docs.racket-lang.org/guide/hash-reader.html but the grammar is rather 
> simple. It would be nice if there is a more complex example.
> 
> On Wednesday, February 14, 2018 at 9:32:23 PM UTC-5, Matthias Felleisen wrote:
> 
> Instead of parsing the raw strings, you might consider the following 
> alternative: 
> 
>  — use read tables to nail down identifier syntax and literal constant syntax 
>  — define all keywords and operators and whatever as plain syntax ids that 
> raise a syntax error 
>  — all remaining things are your identifiers  
>  — now use module-begin to turn the sequence of tokens into a tree where each 
> of your identifiers becomes an actual Racket id 
> 
> I just wrote a neat little paren-free language for optmizing network flows 
> this way and it’s a rather viable strategy. 
> 
> 
> 
>> On Feb 14, 2018, at 5:39 AM, Sorawee Porncharoenwase 
>> <sorawee_por...@brown.edu> wrote:
>> 
>> It works now! I think I simply need a `strip-context` and avoid 
>> `datum->syntax`.
>> 
>> Thank you very much for your help!
>> 
>> On Wednesday, February 14, 2018 at 5:15:06 AM UTC-5, Alexis King wrote:
>> It is worth pointing out that Check Syntax does not see the result of 
>> your reader, it sees the fully-expanded module and performs its analysis 
>> from there. Therefore, it can be useful to use the macro stepper with 
>> macro hiding disabled to inspect the fully-expanded module to make sure 
>> that the information at least appears to be in place. 
>> 
>> In the case of your language, I would use the macro stepper to ensure 
>> the following three things are happening: 
>> 
>>   1. The `sum` identifier appears in binding position in the 
>>      fully-expanded program, and it has the appropriate source location 
>>      information. 
>> 
>>   2. The `sum` identifier also appears in use position in the 
>>      fully-expanded program, and it has distinct source location 
>>      information from the identifier in binding position. 
>> 
>>   3. Both identifiers are syntax-original?. 
>> 
>> If those things are all the case, it’s difficult for me to say much more 
>> without looking at the code itself. 
>> 
>> (As an aside, you should probably be providing the first argument of 
>> my-read-syntax as the first argument to `parse` instead of (object-name 
>> in), but I’m not sure if that’s at all related to the issue here.) 
>> 
>> > On Feb 13, 2018, at 23:33, Sorawee Porncharoenwase 
>> > <sorawee_por...@brown.edu> wrote: 
>> > 
>> > I have a similar problem but I can't figure out a way to fix it yet 
>> > :( 
>> > 
>> > So, when I hover on `sum` on line 3, I get "no bound occurrences". 
>> > That's definitely false since the program runs fine, and `sum` has a 
>> > bound occurrence below (e.g., line 5). 
>> > 
>> > I print the syntax objects passed into `#%module-begin` in the REPL. 
>> > The srcloc seems right to me. 
>> > 
>> > What baffles me further is that when I follow Robby's suggestion to 
>> > insert a printf inside check-syntax code: 
>> > 
>> > (printf "~a ~a ~a\n" stx-obj (syntax-source stx-obj) (syntax-line 
>> > stx-obj)) 
>> > 
>> > I get the following result (only relevant lines shown) 
>> > 
>> > #<syntax temp1> #f #f 
>> > #<syntax temp1> #f #f 
>> > #<syntax:3:20 s> string 3 
>> > #<syntax:3:23 id> string 3 
>> > #<syntax temp1> #f #f 
>> > #<syntax:3:9 id> string 3 
>> > #<syntax f3> #f #f 
>> > #<syntax:5:0 sum> string 5 
>> > #<syntax temp9> #f #f 
>> > #<syntax temp9> #f #f 
>> > #<syntax:7:16 sum> string 7 
>> > #<syntax:7:21 id> string 7 
>> > #<syntax:7:29 id> string 7 
>> > #<syntax temp9> #f #f 
>> > #<syntax:7:10 z> string 7 
>> > ... 
>> > 
>> > So: the sum on line 3 is either missing or somehow becomes `#<syntax 
>> > temp1> #f #f` 
>> > 
>> > And sum on line 7 has a correct srcloc, except that the syntax-source 
>> > somehow changes from `'unsaved-editor` to `string`?!? 
>> > 
>> > FYI, I use megaparsack's `parse-syntax-string` like this: 
>> > 
>> > (define (parse src in) 
>> >   (define len (string-length "#lang recursive-language")) 
>> >   (parse-result! 
>> >    (parse-syntax-string toplevel/p 
>> >                         (datum->syntax #f (port->string in) 
>> >                                        (list src 1 len (add1 len) 0)))) 
>> > 
>> > And this is my module reader 
>> > 
>> > (module reader racket 
>> >   (require syntax/strip-context) 
>> >   (require "parser.rkt") 
>> >   (provide (rename-out [my-read-syntax read-syntax] 
>> >                        [my-read read])) 
>> >   (define (my-read in) (syntax->datum (my-read-syntax #f in))) 
>> >   (define (my-read-syntax _ in) 
>> >     (datum->syntax #f 
>> >       `(module src recursive-language 
>> >         ,@(parse (object-name in) in))))) 
>> > 
>> > Any idea how to fix this? Also feel free to suggest anything that you 
>> > find wrong -- this is the first time I touch the reader! 
>> > 
>> > Thank you :) 
>> 
>> 
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to racket-users...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to