Re: [racket-users] Building "#lang dungeon"
There is http://shill.seas.harvard.edu/ it runs on freebsd. -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/81c4e9b5c1a6a74f27bcbfab528d7d61%40airmail.cc. For more options, visit https://groups.google.com/d/optout.
[racket-users] Compiler Fundamentals: Closure Conversion
Hello everybody, I wanted to share this short literate program/article I wrote that teaches the closure conversion compiler pass. I hope it's useful or interesting to some of you. It is done using the nanopass style. If you've got any questions I will try to answer! #lang racket ;; this is a stand alone simple version of the closure conversion part of the hoist pass from the tarot compiler ;; see https://rain-1.github.io/scheme for more. (require data/queue) ;; closure conversion for lambda calculus ;; ;; the input language is: ;; ;; ::= ;; | ;; | (lambda ( ...) ...) ;; | (begin ...) ;; | ( ...) ;; ;; the output language is ;; ;; ::= (var loc ) ;;| (var env ) ;;| (var glo ) ;;| ;;| (closure ( ...) ) ;;| (begin ...) ;;| ( ...) ;; ;; ::= (var loc ) ;; | (var env ) ;; ;; Variables have been annotated with their storage type and ;; lambda functions have been replaced with closure objects ;; all of the variables captured by a lambda have been packaged ;; up with the closure object HELPERS (define (every p l) (if (null? l) #t (and (p (car l)) (every p (cdr l) (define (index v l) (for/first ([i (in-naturals)] [elt (in-list l)] #:when (equal? elt v)) i)) (define (queue-index v q) (for/first ([i (in-naturals)] [elt (in-queue q)] #:when (equal? elt v)) i)) (define-syntax mapply (syntax-rules () ((mapply f xs arg ...) (map (lambda (x) (f x arg ...)) xs SHAPES (define (var? x) (symbol? x)) (define (datum? x) (or (boolean? x) (number? x))) (define (lambda? x) (if (and (pair? x) (eq? 'lambda (car x))) (if (and (every symbol? (cadr x)) (not (null? (cddr x #t (error "malformed lambda expression" x)) #f)) (define (lambda-bindings x) (cadr x)) (define (lambda-body x) (implicit-begin (cddr x))) (define (begin? x) (and (pair? x) (eq? 'begin (car x (define (application? x) (pair? x)) (define (implicit-begin xs) (if (null? xs) (error "empty expression list") (if (null? (cdr xs)) (car xs) `(begin . ,xs ;; CLOSURE CONVERSION (struct scope (locals env captures globals)) ;; ;; locals is a list of symbols ;; - it's the variables bound by the current lambda alternatively the top stack frame ;; ;; env is a list of symbols ;; - is a list of every non-global variable that has been brought into scope by lambda binders ;; for example in (lambda (a b) (lambda (x y) )) at the point the env is (x y a b) ;; ;; captures is a queue of symbols ;; - If you reference a variable that isn't global or local it'll be captured and put into this queue ;; at the end of processing a subexpression, this queue becomes the closure environment ;; ;; globals is a list of symbols ;; - car, cdr, cons etc. (define (classify var scope) ;; classify a variable with its storage type based on a scope (cond ((index var (scope-locals scope)) => (lambda (i) `(var loc ,i))) ((member var (scope-env scope)) (cond ((queue-index var (scope-captures scope)) => (lambda (i) `(var env ,i))) (else (enqueue! (scope-captures scope) var) (let ((i (- (queue-length (scope-captures scope)) 1))) `(var env ,i) ((member var (scope-globals scope)) `(var glo ,var)) (else (error "unbound variable error" var (define (cc exp sc) (cond ((var? exp) (classify exp sc)) ((datum? exp) exp) ((lambda? exp) (let* ((vars (lambda-bindings exp)) (body (lambda-body exp)) (captures^ (make-queue)) (sc^ (scope vars (append (scope-locals sc) (scope-env sc)) captures^ (scope-globals sc))) (body^ (cc body sc^))) `(closure ,(mapply cc (queue->list captures^) sc) ,body^))) ((begin? exp) `(begin . ,(mapply cc (cdr exp) sc))) ((application? exp) (mapply cc exp sc)) (else (error "malformed expression in cc" exp TESTING, EXAMPLES (define (print x) (display x) (newline)) (define (go exp) (let ((res (cc exp (scope '() '() (make-queue) '(car cdr cons) (print exp) (display "==> ") (print res) (newline))) (define (test) (go '3) (go '(lambda (x) x)) (go '(lambda (x) (car x))) (go '(lambda (x) (x 5 x 7))) (go '(lambda (x y) (x y))) (go '(lambda (x y) (y x))) (go '(lambda (z) (lambda (x y) (y x (go '(lambda (x y) (lambda (z) (y x (go '(lambda (x) (lambda (y) (lambda (z) (x y z)) (test) ;; 3 ;; ==> 3 ;; ;; (lambda (x) x) ;; ==> (closure () (var loc 0)) ;; ;; (lambda (x) (car
Re: [racket-users] Re: Some concern about ChezScheme...
On 2019-02-08 23:01, George Neuner wrote: On Fri, 8 Feb 2019 08:37:33 -0500, Matthias Felleisen wrote: On Feb 6, 2019, at 3:19 PM, George Neuner wrote: The idea that a compiler should be structured as multiple passes each doing just one clearly defined thing is quite old. I don't have references, but I recall some of these ideas being floated in the late 80's, early 90's [when I was in school]. Interestingly, LLVM began (circa ~2000) with similar notions that the compiler should be highly modular and composed of many (relatively simple) passes. Unfortunately, they quickly discovered that, for a C compiler at least, having too many passes makes the compiler very slow - even on fast machines. Relatively quickly they started combining the simple passes to reduce the running time. I strongly recommend that you read the article(s) to find out how different nanopasses are from the multiple-pass compilers, which probably date back to the late 60s at least. — Matthias I did read the article and it seems to me that the "new idea" is the declarative tool generator framework rather than the so-called "nanopass" approach. The distinguishing characteristics of "nanopass" are said to be: (1) the intermediate-language grammars are formally specified and enforced; (2) each pass needs to contain traversal code only for forms that undergo meaningful transformation; and (3) the intermediate code is represented more efficiently as records IRs implemented using records/structs go back to the 1960s (if not earlier). Formally specified IR grammars go back at least to Algol (1958). I concede that I am not aware of any (non-academic) compiler that actually has used this approach: AFAIAA, even the Algol compilers internally were ad hoc. But the *idea* is not new. I can recall as a student in the late 80's reading papers about language translation and compiler implementation using Prolog [relevant to this in the sense of being declarative programming]. I don't have cites available, but I was spending a lot of my library time reading CACM and IEEE ToPL so it probably was in one of those. I'm not sure what #2 actually refers to. I may be (probably am) missing something, but it would seem obvious to me that one does not write a whole lot of unnecessary code. The article talks about deficiencies noted with various support tools and drivers that were provided to aid students in implementing so-called "micropass" compilers, but who wrote those tools? Not the students. If there was much superfluous code being used or generated, well whose fault was that? Aside: I certainly could see it being a reaction to working with Java where tree walking code has to be contorted to fit into the stupid multiple dispatch and vistor patterns. YMMV, (and it will) George Could nanopass, at least in theory, fuse multiple (or even all) passes into one at compile time. To create a very efficient compiler which is also logically broken down and readable in the source code? -- 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.
Re: [racket-users] Github collection for making a language
On 2019-01-24 17:03, Stephen De Gabrielle wrote: Hi, GitHub has a feature called ‘Collections’ https://github.com/collections that are community generated content. e.g. https://github.com/collections/choosing-projects I thought I’d make one for ‘How to make your own PL’ I’ve come up with an initial list of resources that would be suitable for a developer wanting to prototype a new language: --- items: - http://beautifulracket.com [1] - mbutterick/beautiful-racket - http://www.greghendershott.com/fear-of-macros/ - https://cacm.acm.org/magazines/2012/1/144809-creating-languages-in-racket/fulltext - https://docs.racket-lang.org/guide/languages.html - bennn/forth display_name: How to make your own programming language created_by: spdegabrielle image: create-a-language.png --- Have an idea for making your own programming language? Here’s how to get started prototyping a new language. --end-- https://raw.githubusercontent.com/spdegabrielle/explore/make-your-own-PL/collections/make-programming-languages/index.md I think beautiful racket, and fear-of-macros are essential, but I feel I lack resources for - Creating other styles of syntax: e.g. c/java, python, ruby, smalltalk, forth, etc. - A video with a good quality image - IDE(DrRacket) support for new language - Small example respositories e.g. is bennn/forth a good choice? Any suggestions or changes appreciated. Kind regards, Stephen-- -- 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. Links: -- [1] http://beautifulracket.com/ Hi Stephen, It is quite simple to make a language using racket-peg to parse and transforming the object language down into the host racket language, here is an example https://github.com/rain-1/nand-lang -- 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.
Re: [racket-users] Escaping strings for the shell
On 2018-12-29 19:08, David Storrs wrote: On Fri, Dec 28, 2018 at 11:34 PM Jack Rosenthal wrote: On Fri, 28 Dec 2018 at 23:09 -0500, David Storrs wrote: > I am using 'system' to offload some work onto wget and other > applications in a few one-off scripts. Is there an easy way to escape > a string so it's suitable for usage in the shell? Things like > backwhacking all the quotes and relevant spaces and such. Is avoiding the shell altogether an option? You could use "system*" Not really: Welcome to Racket v6.11. ; two argument strings (system* "/usr/local/bin/wget" "http://google.com; "-O /tmp/fooflaksdjdghk") /tmp/fooflaksdjdghk: No such file or directory #f ; one argument string (system* "/usr/local/bin/wget" "http://google.com -O /tmp/fooflaksdjdghk") --13:47:10-- http://google.com%20-o%20/tmp/fooflaksdjdghk => `fooflaksdjdghk' Resolving google.com -o ... failed: nodename nor servname provided, or not known. #f Okay, it's transforming -O into -o. Let's try the long form: (system* "/usr/local/bin/wget" "http://google.com; "--output-document=/tmp/zot") ...lots of spew... #t Yep, that works. Okay, now let's try it with an actual filename, unescaped to start. I expect this to fail: (system* "/usr/local/bin/wget" "http://google.com; "--output-document=/tmp/Sara's birthday, 9/12/01-18/181") /tmp/Sara's birthday, 9/12/01-18/181: No such file or directory #f Sure enough. Oh good, we're back to shell-style escapes where all this started. You just did it wrong. SYSTEM* is actually useful in this situation. (system* "/usr/local/bin/wget" "http://google.com; "-O" "/tmp/fooflaksdjdghk") The -o needed to be a separate argv parameter. -- 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.
Re: [racket-users] Converting bulleted list to s-expression?
As an example, this... - a - b c - d e f - g h would get transformed into something like this... '(a (b c) (d e f (g h))) You can implement this in 2 stages. Stage 1 is line based parsing, turn the input text into this list: '((0 a) (2 b c) (2 d e f) (4 g h))) the number is the indent level. This part is quite easy, you could do this with regex. Stage 2 is a bit more difficult, the algorithm to do this is based on recursive stream processing. You are reading or 'parsing' a tree off of a flat string of indent levels. When processing a head at indent level N you read off all the subtrees at indent level >N you can see, then return two values: the tree and the remainder of the stream. (define (collect inputs) (let-values (((h t) (collect^ inputs))) (unless (null? t) (error 'collect "failed to collect everything" t)) h)) (define (collect^ inputs) (let ((indent (caar inputs)) (head (cdar inputs)) (inputs (cdr inputs))) (n-collect indent head inputs))) (define (n-collect n head stream) ;; n-collect will collect up all ;; subtrees off the stream whose ;; level is > N (let loop ((subtrees '()) (stream stream)) (if (or (null? stream) (<= (caar stream) n)) (values (append head (reverse subtrees)) stream) (let-values (((subtree stream) (collect^ stream))) (loop (cons subtree subtrees) stream) -- 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.
[racket-users] Racket PEG parser library release 0.3
Hello! Released by PEG parser library version 0.3 today. It has got semantic actions now, which lets you parse and transform at the same time. I hope the code is useful and interesting to you. It can easily be installed via the racket package manager as "peg" and there are docs here: - https://pkgs.racket-lang.org/package/peg There is also a example of using it quickly mock up a new #lang - https://github.com/rain-1/nand-lang -- 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.
[racket-users] difficult to package library
Hi. I want to package my library for https://pkgs.racket-lang.org but I can't figure out how to do the info.rkt file. I would like my repo to be like this: * repo/peg/codehere.rkt like main.rkt peg.rkt etc. * repo/tests/ my tests * repo/scribblings/peg.scrbl the documentation is this directory structure OK? I have not been able to make it work so I have moved everything from repo/peg/ into repo/. but I am getting "dependency problems" and documentation is not built: http://pkg-build.racket-lang.org/server/built/deps/peg.txt I can't figure out how to make the correct info.rkt file either way, and it is difficult to test because I have to update the pkgs page and wait. So some advice would be very helpful. Thanks. -- 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.
Re: [racket-users] announcement: racket-peg release 0.2
On 2018-04-14 16:57, David Storrs wrote: Sounds interesting. Is there any documentation on it aside from the README? Yes, It's documented here http://docs.racket-lang.org/peg/index.html and the examples in the repo should be a good resource for using the library too. Don't hesitate to make a github issue if there is anything lacking! -- 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.
[racket-users] announcement: racket-peg release 0.2
hello! I have created a PEG parser library for racket. It's basically regex turned up to 11. It lets you write parsers like this: (define-peg marked-palindrome (or "m" (and "1" marked-palindrome "1") (and "0" marked-palindrome "0"))) or like this: #lang peg expr <- sum ; sum <-- (product ('+' / '-') sum) / product ; product <-- (value ('*' / '/') product) / value ; value <-- number / '(' expr ')' ; number <-- [0-9]+ ; It is available from the racket pkgs repository, or on github: * https://pkgd.racket-lang.org/pkgn/package/peg * https://github.com/rain-1/racket-peg I welcome feedback and hope that the library is of use. -- 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.
[racket-users] documentation and tests not running on racket pkgs
Hello, I uploaded my package 3 days ago https://pkgs.racket-lang.org/package/peg but the documentation and tests have not been run. I was told it should happen every 24 hours. I am not sure if I created my package slightly wrong or if the build server has a bug. -- 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.