skew70
2021-3-7 13:40:13

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.


spdegabrielle
2021-3-7 13:40:16

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") ;; &lt;&lt;this is where I'm lost&gt;&gt; ;; now I need my language (define-syntax-rule (module-begin expr ...) (#%module-begin expr ;this evaluates the first expression -&gt; (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


mflatt
2021-3-7 13:43:01

It’s a bug that has been fixed for the next version.


mflatt
2021-3-7 13:43:47

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.


spdegabrielle
2021-3-7 13:56:09

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


mflatt
2021-3-7 13:57:42

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?


spdegabrielle
2021-3-7 14:12:30

Private - only used by the ~a -


spdegabrielle
2021-3-7 14:14:23

Though the output of ~a will be included in Scribble via a dynamic require


mflatt
2021-3-7 14:20:44

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.


spdegabrielle
2021-3-7 15:11:10

Thanks !


ben.knoble
2021-3-7 17:42:55

I’ve found that https://beautifulracket.com/ is a really good reference


hazel
2021-3-7 19:59:57

is there anything analagous to remove-duplicates for vectors (or should I just write it myself)


hectometrocuadrado
2021-3-7 20:05:26

How allocator works? With the following code:


hectometrocuadrado
2021-3-7 20:05:40

DrRacket crashes


hectometrocuadrado
2021-3-7 20:06:29

I expected “Create 6 Create 6 Create 5 Create 6 Destroy 6 Destroy 5 Destroy 6 Destroy 6”



soegaard2
2021-3-7 20:07:30

Does it work, if you remove the printf and the display?


soegaard2
2021-3-7 20:08:23

The allocator is called in atomic mode:


hectometrocuadrado
2021-3-7 20:09:02

Oh, I see


hectometrocuadrado
2021-3-7 20:09:11

It works without display


hectometrocuadrado
2021-3-7 20:09:17

Thanks!


hectometrocuadrado
2021-3-7 20:09:50

At least, my thoughts about how it works are right, true?


sorawee
2021-3-7 20:10:20

I’m not aware of remove-duplicates counterpart for vector. I would have written one myself.


soegaard2
2021-3-7 20:10:45

I think so.


soegaard2
2021-3-7 20:11:06

I have never used allocator for anything.


hectometrocuadrado
2021-3-7 20:11:15

Well, if I get errors I will come back :smile:


hectometrocuadrado
2021-3-7 20:12:01

I’m going to use it with the vulkan api integration. I have to make explicit calls to destructors


hectometrocuadrado
2021-3-7 20:13:00

And I prefer having an automatic deallocator when program ends


spdegabrielle
2021-3-7 20:31:59

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}


soegaard2
2021-3-7 20:33:38

Hmm. If #lang s-exp "bib-lang.rkt" works, shouldn’t #lang at-exp "bib-lang.rkt" work too?


spdegabrielle
2021-3-7 20:36:01

Sadly I get bib-lang-test.scrbl:1:6: bad language path following at-exp: "bib-lang.rkt"


raoul.schorer
2021-3-7 20:39:54

Is there a way to make a bit-vector immutable, please?


soegaard2
2021-3-7 20:43:37

But it works for s-exp? Then maybe, at-exp could be improved.

But maybe you can write #lang at-exp bib-lang ?


soegaard2
2021-3-7 20:46:11

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


spdegabrielle
2021-3-7 20:49:52

maybe. I have to install it as a collection standard-module-name-resolver: collection not found


raoul.schorer
2021-3-7 20:53:19

I see. Thanks!


spdegabrielle
2021-3-7 21:09:35

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}


notjack
2021-3-7 21:20:50

if you feel like using rebellion : (require rebellion/collection/vector rebellion/streaming/transducer) (transduce myvector (deduplicating) #:into (into-vector))


notjack
2021-3-7 21:22:09

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



raoul.schorer
2021-3-7 21:42:06

Ah, I’ll check it out! Thanks.