I just installed racket on a Mac, and I’ve found some odd behavior with the debugger’s Step button. If I click Step once, clicking it a second time does nothing. I have to move my cursor off of the button entirely, and then move it back on the button in order to be able to Step to the next instruction. Is this expected? It seems like a really annoying and non-standard button behavior in any GUI.
admission: I’ve never made a language - or used macros- but I want to make a simple one!
From looking at the <https://docs.racket-lang.org/guide/module-languages.html#%28part._s-exp%29|guide on languages> I’ve worked out I need to create a macros that turn (author “aaa”) into (define a “aaa”) - and makes ‘a’ in the scope I can use it to concatenate the two strings (title “ggdf”) into (define title “ggdf”) - ^ ditto for ‘t’ and a ‘module-begin’ macro that concatenates ‘a’ and ‘t’ and returns the value
I’ve got this far - any suggestions appreciated.
bib.rkt
#lang racket
(require racket/format)
(provide (except-out (all-from-out racket)
#%module-begin)
(rename-out [module-begin #%module-begin])
author title)
;; I need to define macros for author and title
;; that transform (author "stephen") to (define a "stephen")
;; and
;; that transform (title "a title") to (define t "a title")
;; <<this is where I'm lost>>
;; now I need my language
(define-syntax-rule (module-begin expr ...)
(#%module-begin
expr ;this evaluates the first expression -> (author "stephen") setting a to be "stephen"
... ;this evaluates any subsequent expressions doing the same
(~a "Author: " a ", title:" t) ;; this uses `a` and `t`
))
the idea is code in the bib language looks like this #lang s-exp "bib.rkt"
(title "Adding Interactive Visual Syntax to Textual Code")
(author "Andersen, Ballantyne, Felleisen")
and when run returns; Author:Andersen, Ballantyne, Felleisen title:Adding Interactive Visual Syntax to Textual Code
It’s a bug that has been fixed for the next version.
You can get a snapshot from http://snapshot.racket-lang.org\|snapshot.racket-lang.org if the bug is annoying enough to be worth upgrading.
I thought this was right
#lang racket
(require racket/format)
(provide (except-out (all-from-out racket)
#%module-begin)
(rename-out [module-begin #%module-begin])
author
title)
(define-syntax-rule (author expr) (define aut expr))
(define-syntax-rule (title expr) (define titl expr))
(define-syntax-rule (module-begin expr ...)
(#%module-begin
expr
...
(~a aut "," titl)))
but
#lang s-exp "bib.rkt"
(title "Queen of Diamonds")
(author "Lewis")
gives me an error:
bib.rkt:17:7: aut: unbound identifier in: aut
So it is a scope problem? Any hints appreciated
Yes, it’s a scope problem. Is your intent that aut
and titl
are bindings that are visible to other expressions in a language that uses “bib.rkt”? Or are they only supposed to be private and used by the generated ~a
expression?
Private - only used by the ~a -
Though the output of ~a will be included in Scribble via a dynamic require
One possible solution is to effectively cancel the way macro expansion makes separate macro expansions of author
and title
created different bindings by using syntax-local-introduce
— which is an expand-time operations, so you have to get into the business of writing expand-time code and moving between phases with syntax-parse
and #,
. #lang racket
(require racket/format
(for-syntax racket/base
syntax/parse))
(provide (except-out (all-from-out racket)
#%module-begin)
(rename-out [module-begin #%module-begin])
author
title)
(define-syntax (author stx)
(syntax-parse stx
[(_ expr) #`(define #,(syntax-local-introduce #'aut) expr)]))
(define-syntax (title stx)
(syntax-parse stx
[(_ expr) #`(define #,(syntax-local-introduce #'titl) expr)]))
(define-syntax (module-begin stx)
(syntax-parse stx
[(_ expr ...)
#`(#%module-begin
expr
...
(~a aut "," titl))]))
The aut
and titl
variables will still be invisible to code in the “bib.rkt” language, since the identifiers still have the enclosing “bib.rkt” module in their scopes.
Thanks !
is there anything analagous to remove-duplicates
for vectors (or should I just write it myself)
How allocator works? With the following code:
DrRacket crashes
I expected “Create 6 Create 6 Create 5 Create 6 Destroy 6 Destroy 5 Destroy 6 Destroy 6”
Does it work, if you remove the printf and the display?
The allocator is called in atomic mode:
Oh, I see
It works without display
Thanks!
At least, my thoughts about how it works are right, true?
I’m not aware of remove-duplicates
counterpart for vector
. I would have written one myself.
I think so.
I have never used allocator
for anything.
Well, if I get errors I will come back :smile:
I’m going to use it with the vulkan api integration. I have to make explicit calls to destructors
And I prefer having an automatic deallocator when program ends
I’m still on my language creation task. (I’ve got my <https://docs.racket-lang.org/guide/module-languages.html|module language >working - Thank you Matthew) #lang s-exp "bib-lang.rkt"
(title "a new day")
(author "b baggins")
(date "23-March-2021")
(location "London")
(url "<https://racket-lang.org>")
(category "hobbit")
Is there a way I can make my language use the scribble or at-exp
reader, instead of s-exp
or defining my own reader? #lang at-exp "bib-lang.rkt"
@title{a new day}
@author{b baggins}
@(date "23-March-2021")
@location{London}
@url{<https://racket-lang.org>}
@category{hobbit}
Hmm. If #lang s-exp "bib-lang.rkt"
works, shouldn’t #lang at-exp "bib-lang.rkt"
work too?
Sadly I get bib-lang-test.scrbl:1:6: bad language path following at-exp: "bib-lang.rkt"
Is there a way to make a bit-vector
immutable, please?
But it works for s-exp? Then maybe, at-exp could be improved.
But maybe you can write #lang at-exp bib-lang
?
I think the answer is no.
You’ll need to implement immutable-bit-vector in a different manner.
FWIW the code is here: https://github.com/racket/racket/blob/master/racket/collects/data/bit-vector.rkt
maybe. I have to install it as a collection standard-module-name-resolver: collection not found
I see. Thanks!
Ahh !
> The https://docs.racket-lang.org/scribble/reader-internals.html?q=at-exp#%28mod-path._at-exp%29\|at-exp language installs https://docs.racket-lang.org/scribble/reader.html?q=at-exp\|@-reader support in the readtable used to read a module, and then chains to the reader of another language that is specified immediately after https://docs.racket-lang.org/scribble/reader-internals.html?q=at-exp#%28mod-path._at-exp%29\|at-exp. It lives!
#lang at-exp s-exp "bib-lang.rkt"
@title{a new day}
@author{b b baggins}
@(date "23-March-2021")
@location{London}
@url{<https://racket-lang.org>}
@category{hobbit}
if you feel like using rebellion
: (require rebellion/collection/vector
rebellion/streaming/transducer)
(transduce myvector (deduplicating) #:into (into-vector))
there’s rebellion/binary/bitstring
which is an immutable bit vector, if you feel like using third-party packages https://docs.racket-lang.org/rebellion/Bitstrings.html
Ah, I’ll check it out! Thanks.