
@laurent.orseau I need something that can read a bf program file as input and then execute it on the fly. So we don’t have to copy and paste every existing bf program into a file starting with #lang bf
.

Ahhh, I get it now, sorry I’ve been slow :slightly_smiling_face: Then what you’re currently doing, IIUC, seems fine: eval the module form to create a module, then use dynamic-require to visit it.
Maybe there’s a better way by expanding only the module
macro, but I’m not sure—someone else may know more.
(Otherwise, generating a temporary file to just use dynamic require seems suboptimal.)

What’s the best way to visit a module from an input string (not file)? It’s possible with eval
to create the module, then dynamic-require
to visit it, but is it possible to use something smarter than eval
? (cc @wanpeebaw)

@soegaard2 > Have you seen http://calmerthanyouare.org/2015/01/07/optimizing-brainfuck.html Yes, thanks for mention this article. I once implemented “Contraction” and “Clear loops” in my Java implementation, which reduce the execution time about 10x. I think it should be roughly the same in Racket. But I want to left these optimizations behind, and look at the capabilities of the Racket language and compiler itself first.
I saw some translation based (jit) implementations in other languages. I thought it should be easier to implement in Racket instead of C or Java because I heard Lisp-family are good at meta-programming. So I give it a try.

@laurent.orseau Found one related discussion… https://stackoverflow.com/questions/56197296/how-to-require-a-racket-module-that-doesnt-have-a-lang-header-line

What’s wrong with eval
? Since the string is only known at runtime, eval
seems to be the most fitting solution.

It’s not necessarily wrong, but I was wondering if there was something more tailored to this case (hence possibly with better error reporting, faster, etc.).

well sandbox allows for more customization i suppose? and i think that you can port-count-lines!
for better error messages? dont quote me on that though, have not tested it.

Beginner Question about PLT Redex I try to model my language (stlc with subtyping) in Redex, I found that the syntax of two resources are not the same, both are valid I guess. • https://github.com/racket/redex/blob/master/redex-examples/redex/examples/stlc.rkt • https://williamjbowman.com/doc/experimenting-with-redex/sec_syntax.html#%28part._.Syntax_.T.L.D.R%29 I’m not sure which syntax is the recommended way to go :disappointed: btw considering the examples in racket/redex repo is kinda old (6 years ago), are there any “new” examples I can refer to? (I’ve already checked with http://prl.ccs.neu.edu/blog/2017/09/25/plt-redex-faq/)

Yup will do, need to get together all the deets.

My favorite “big” Redex example is Van Horn’s introduction to AAM: https://dvanhorn.github.io/redex-aam-tutorial/\|https://dvanhorn.github.io/redex-aam-tutorial/

And if you have the book “Semantics Engineering with PLT Redex” the whole second part is an extensive introduction (the third part is case studies). There are a few gaps because of its age (like binding forms) but it is definitely still relevant.

When using ffi to interface with C functions, and say one of the parameters is a pointer to an int void func(int* p1, ...)
then the ffi definition would look like such (_fun _pointer ... ->)
when I call this function what would I pass to it? How do I create a _pointer that I can pass it, and then after the call how to read the value the _pointer is pointing at?

Using _pointer
is usually a last resort. Using (_ptr i _int)
is more likely to be useful.

or perhaps (_ptr io _int)
if the function is going to modify the pointer.

I’ve found https://jblevins.org/projects/deft/\|Deft handy for searching through a directory of notes (either .txt or .org).

I’m trying to understand how symbols are GC’d, and I’m confused by this sentence in the reference “Interned and unreadable symbols are only weakly held by the internal symbol table.” Should it be “uninterned”? I can’t seem to make an example where an interned symbol is collected. Replacing ’foo with an uninterned symbol results in it being collected. #lang racket
(define w (make-weak-box 'foo))
(collect-garbage)
(weak-box-value w) ; expected #f, got 'foo

Uninterned symbols aren’t in the symbol table at all.

Right, but I still don’t understand when an interned symbol is collected.

My reading of the docs are that ’foo is weakly held by the symbol table, so w ought to be cleared out in my example, but it’s not.

'foo
might be there in the code. What if you create it with string->symbol
?

same

But maybe that’s just the result of optimization?

ok cool I will try that

I think that’s it. If I do (string->symbol (read-line))
it gets cleared out.

See also this recent thread: https://racket.slack.com/archives/C06V96CKX/p1605277145105400

thanks!

I see that there’s a problem using a 32-bit Racket to build 64-bit boot files. I’ll investigate that further.

(_ptr io _int)
compiled successfully however I am not receiving the expected value as a return, it seems that the value after the call is just being return as whatever I initialized it to.

Take a look at the example in the docs for _ptr

I’m guessing that you were trying to use the 32-bit Arm build to bootstrap a AArch64 build. Was that because you used something like make RACKET=…
in the root directory of the Git repo checkout? If you just use make
, then it will bootstrap a different way (via portable-bytecode bootfiles are that fetched from another Git repo) and that should work.

@camoy Aha, thanks for the link. There’s also a OPLSS talk attached with this, they’re both helpful to me.

I downloaded a snapshot racket but I thought it was supposed to be AArch64? I was going to use it, but it couldn’t find libcrypto
which is why I tried to build my own.
So I know, should I just run make
without any args from the top level of the repo?

You might be happier with make base
(which will build a lot less stuff)

at least until you’re sure it works

Ah cool thanks. Is there a snapshot build for AArch64?

I’m not sure whether the snapshots here are for aarch64: https://www.cs.utah.edu/plt/snapshots/, they might be 32-bit

ARMv6 => 32-bit

ahhhhhh okay my bad

I must have picked up a 32bit build

So i do need to build my own then

There are no AArch64 snapshots, currently. When we’re back to a world where I’m in my office, I’ll probably set that up.

FWIW I’ve been building my own 32bits on my Raspberry Pi 3 so these snapshots will help there. Will take another swing at building for 64bit and report back. Thanks for your help!

Bootstrapping with a 32-bit build should have worked, but it turns out that there was some confusion about compile-time fixnums versus run-time fixnums in the bootstrap-via-Racket implementation. Apparently, I had just never tried that.

I should add “32-bit” to the ARMv6 label on the snapshot page. It’s redundantly added everywhere else, after all.

@samth So I am working on adding the functionality to use shaders in sgl
, and I believe that I am writing some of the functions correctly but I don’t seem to be getting the expected output do you think you might be check if this looks correct?

gl.rkt
(define-foreign glCreateShader _gl-enum -> _gl-uint)
...
(define-enum GL_VERTEX_SHADER #x8B31)
(define-enum GL_FRAGMENT_SHADER #x8B30)
gl spec GLuint glCreateShader( GLenum shaderType);

Is/was there a known issue in 7.9CS on Mac where you cannot save a file in DrRacket?

Terminal error message: 2020-11-23 10:36:49.257 DrRacket[48686:11602403] +[NSXPCSharedListener endpointForReply:withListenerName:]: an error occurred while attempting to obtain endpoint for listener 'com.apple.view-bridge': Connection interrupted
2020-11-23 10:36:49.260 DrRacket[48686:11602375] endSheet:returnCode: requires a non-nil sheet

This is on Catalina. DrRacket 7.8CS works fine.

Are you saving to some sort of network drive

No. Looking at some similar (non-Racket) reports indicates maybe I haven’t given DrRacket 7.9 all of the needed permissions

“System Preferences” > “Security & Privacy” > “Privacy” > “Full Disk Access” Then make sure “DrRacket” is checked. That fixed it.

Dunno why 7.8 worked. This is a newish laptop maybe my $EMPLOYER copied settings from my old laptop.

I think you can get equally good error message by read
-ing the input string into a syntax object first (with port-count-lines!
) and then eval
it.
My guess is that sandbox is not going to be faster than eval
. In fact, it could be slower.

Can you add that to the wiki?

Sure. In the FAQ?

I think in gettign started.


I remember reading somewhere that Racket removed mutable pairs and list?
stores a flag on the head pair so it’s constant time rather than O(n)
. 1) Am I dreaming? 2) Is it still the case in CS 3) Does Racket store the length of the list as well (like Java’s LinkedList implementation)?

Racket doesn’t store the length.
In Racket CS, it doesn’t store the “list” flag on every pair, but it does store the flag in some pairs in a way that if you call list?
several times, the cost on average is constant. I.e., amortized constant time.

What is the golden standard for docstrings/ contracts stuff in Racket?
There seems to be a “design recipe” mentioned in HtDP, but I was curious if that is being used out there to write Racket programs in the real world so I could be more consistent with those as well.
Some examples of big OSS programs written in Racket that I found out in the real world include @greg’s racket https://github.com/greghendershott/markdown\|markdown, matthew buttericks https://github.com/mbutterick/pollen, or @lexi.lambda’s hackett https://github.com/lexi-lambda/hackett.
All seem to have minimal levels of documentation, and when they do have documentation, it’s a few lines before the procedure definition, each prefixed by ;;
describing what the function does (from a cursory glance, don’t want to generalize, but ya), and not much to do with the design recipe that HtDP seems to have going on, so I was just wondering what to do for my project.
Context: I am a student. I am writing a big-ish project in Racket. There’s only like 2 people in my class who are doing this “project” in Racket. But, we get marked on proper documentation of our code. So, just wondering what the most efficient way to document it would be. Also, I want this documentation to be good so I can come back 2–3 years later and understand immediately what’s happening in my code

Tangent 1: Today is the first time I have ever looked at HtDP lol… (was looking mostly at the http://docs.racket-lang.org\|docs.racket-lang.org), so was wondering where the “Design recipe” is formally defined if anyone knows Tangent 2: Why is it so hard to find big OSS projects written in your favourite languages lol… Thankfully I found this: https://github.com/caocao485/awesome-racket-and-scheme but man it should be easier to find OSS projects written in Racket or any other language for that matter

I sometimes write the contract unofficially as a comment.
For functions that I will provide
so that users can use, I don’t write the documentation in the code, because I will do that in Scribble instead.

There are (of course) several ways of doing things. I think, the general consensus is that documentation is too important to have in docstrings — proper documentation in the form of a “real” scribble document is better.
However the down side is that internal functions might not we as well documented as one might want.
Here is another data point: https://github.com/soegaard/metapict/blob/master/metapict/color.rkt
I believe contracts are is a good thing - but I haven’t used them consistently in metapict.
As an extreme, this file contains more documentation than code (and only exports a single function):
https://github.com/soegaard/sci/blob/master/flomat/expm.rkt
It illustrates the point, that intricate code needs more comments than usual.

But I mean, if you are being graded, then just fully follow the design recipe?
Personally, I think the design recipe is great when you are “blanked” and have no idea how to approach the problem. That’s why introductory classes want you to practice it: so that students who are blanked have something to work on.
But if you have a rough idea for what to do, then several steps can be skipped IMO.
For example, I don’t write examples for the sake of figuring out how to implement a function, because I usually know how to implement a function already.
I still do write tests though, to ensure that my function is correct.

Thank you both for the suggestions :slightly_smiling_face: @badkins I also use org-journal
, which also seems to be great for searching. Although the entries are indexed by date and not topic in this case hmm..

> But I mean, if you are being graded, then just fully follow the design recipe? This would mean I would actually have to learn the design recipe (never read HtDP and was never really taught it, gonna have to page through the book to see where it is formally defined, as I said in Tangent 1 below lol) Unfortunately this is mostly an independent assignment and people mostly chose C++ for this task (making a compiler). Since it’s so independent, the criteria is just “have good documentation”, so technically I guess it’s not limited to docstrings?
Although that would be the usual implication in C++ however. Maybe just adding some basic things like (match val-expr clause ...)
clause = [pat body ...+]
\| [pat (=> id) body ...+]
\| [pat #:when cond-expr body ...+]
or something would be a good idea, maybe even right in the .rkt
file as an “ad hoc” doc string.
w.r.t Scribble, never used it, so dunno how hard it would be to get started. Might be worth learning the basics right now however. Gonna check with the profs if making an external html files is ok (also not sure if Scribble outputs directly to html lol)

Ye, maybe just a Scribble with one-line descriptions of each procedure, and contracts would be good and minimalist

> Gonna check with the profs if making an external html files is ok (also not sure if Scribble outputs directly to html lol) Scribble generates html - all the racket documentation is in scribble

Figure 5: The basic steps of a function design recipe
A more extended treatment is here: https://courses.edx.org/courses/course-v1:UBCx+SPD1x+2T2015/77860a93562d40bda45e452ea064998b/

Scribble introduction https://docs.racket-lang.org/scribble/getting-started.html
Setting up library documentation: https://docs.racket-lang.org/scribble/how-to-doc.html#%28part._setting-up%29
the scribble ‘manual’ support https://docs.racket-lang.org/scribble/manual.html

if I have an instance of class foo
how do I call foo’s method bar
?

(send a-foo bar <args> ...)

Thank you . It seems that HtDP uses something of this sort though: ; Los -> Boolean
; does l contain "dog"
(define (contains-dog? l)
(cond
[(empty? l) #false]
[else
(or
(string=? (first l)
"dog")
(contains-dog?
(rest l)))]))
; Los -> Boolean
; does l contain "cat"
(define (contains-cat? l)
(cond
[(empty? l) #false]
[else
(or
(string=? (first l)
"cat")
(contains-cat?
(rest l)))]))
while the Racket Reference uses this notation (different, slightly?): (cons a d) → pair?
a : any/c
d : any/c
So probably I will try and stick to the notation used in the Racket Reference to be consistent with that

How does one make a user-extensible macro like require
or match
?

The very short answer is define-syntax
and syntax-local-value

Trying to find the real good paper that has more detail …

I think this is the one I was thinking of: https://www.cs.utah.edu/plt/publications/jfp12-draft-fcdf.pdf

Somehow I missed this talk earlier, but I enjoyed it today. https://youtu.be/R-hy8xLlkHA


That’s also true of Racket BC (there’s a flag in every cons cell but they don’t all get set).

https://arxiv.org/abs/1106.2578\|https://arxiv.org/abs/1106.2578 might be more helpful


While it looks nicer to use sandbox evaluator than use eval directly. I got following error when using the sandbox evaluator. program::-1: ?: access disallowed by code inspector to protected variable
from module: '#%unsafe
at: bytes-set!
in: unsafe-bytes-set!

Or if you really want to be on the cutting edge: https://www2.ccs.neu.edu/racket/pubs/oopsla20-bkf.pdf\|https://www2.ccs.neu.edu/racket/pubs/oopsla20-bkf.pdf

That OOPSLA ’20 paper is very exciting. Is the API it presents being added to Racket?

The code is available here which I think Michael is cleaning up and documenting in the coming days: https://github.com/michaelballantyne/ee-lib\|https://github.com/michaelballantyne/ee-lib