wanpeebaw
2020-11-23 08:28:24

@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.


laurent.orseau
2020-11-23 09:16:09

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.)


laurent.orseau
2020-11-23 09:19:12

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)


wanpeebaw
2020-11-23 10:41:15

@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.


wanpeebaw
2020-11-23 10:58:10

sorawee
2020-11-23 11:31:56

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


laurent.orseau
2020-11-23 12:53:35

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.).


cris2000.espinoza677
2020-11-23 13:07:35

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.


xuxue
2020-11-23 13:08:29

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.rkthttps://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/)


d_run
2020-11-23 13:43:35

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


camoy
2020-11-23 14:56:59

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/


camoy
2020-11-23 15:01:30

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.


matthew.smith16
2020-11-23 15:09:00

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?


samth
2020-11-23 15:16:57

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


samth
2020-11-23 15:17:42

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


badkins
2020-11-23 15:22:04

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


dvanhorn
2020-11-23 15:23:53

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


samth
2020-11-23 15:27:07

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


dvanhorn
2020-11-23 15:29:18

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


dvanhorn
2020-11-23 15:29:55

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.


samth
2020-11-23 15:30:25

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


dvanhorn
2020-11-23 15:30:30

same


dvanhorn
2020-11-23 15:30:45

But maybe that’s just the result of optimization?


matthew.smith16
2020-11-23 15:32:06

ok cool I will try that


dvanhorn
2020-11-23 15:32:28

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


mflatt
2020-11-23 15:34:33

dvanhorn
2020-11-23 15:37:21

thanks!


mflatt
2020-11-23 15:43:39

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


matthew.smith16
2020-11-23 15:43:44

(_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.


samth
2020-11-23 15:44:06

Take a look at the example in the docs for _ptr


mflatt
2020-11-23 15:46:08

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.


xuxue
2020-11-23 16:20:51

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


d_run
2020-11-23 16:49:27

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?


samth
2020-11-23 16:49:52

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


samth
2020-11-23 16:50:01

at least until you’re sure it works


d_run
2020-11-23 16:50:10

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


samth
2020-11-23 16:51:24

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


mflatt
2020-11-23 16:52:23

ARMv6 => 32-bit


d_run
2020-11-23 16:52:43

ahhhhhh okay my bad


d_run
2020-11-23 16:52:56

I must have picked up a 32bit build


d_run
2020-11-23 16:53:16

So i do need to build my own then


mflatt
2020-11-23 16:53:17

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.


d_run
2020-11-23 16:53:57

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!


mflatt
2020-11-23 16:54:43

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.


mflatt
2020-11-23 16:57:30

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


matthew.smith16
2020-11-23 18:15:10

@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?


matthew.smith16
2020-11-23 18:17:02

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);


samdphillips
2020-11-23 18:32:43

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


samdphillips
2020-11-23 18:37:17

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


samdphillips
2020-11-23 18:38:56

This is on Catalina. DrRacket 7.8CS works fine.


spdegabrielle
2020-11-23 18:39:09

Are you saving to some sort of network drive


samdphillips
2020-11-23 18:41:49

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


samdphillips
2020-11-23 18:48:16

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


samdphillips
2020-11-23 18:49:04

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


sorawee
2020-11-23 19:52:51

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.


spdegabrielle
2020-11-23 20:26:35

Can you add that to the wiki?


samdphillips
2020-11-23 20:59:35

Sure. In the FAQ?


spdegabrielle
2020-11-23 21:00:01

I think in gettign started.



yilin.wei10
2020-11-23 21:10:17

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)?


sorawee
2020-11-23 21:36:53

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.


phanthero
2020-11-23 22:03:00

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


phanthero
2020-11-23 22:04:39

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


sorawee
2020-11-23 22:10:52

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.


soegaard2
2020-11-23 22:12:46

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.


sorawee
2020-11-23 22:16:46

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.


phanthero
2020-11-23 22:17:38

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..


phanthero
2020-11-23 22:41:33

> 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)


phanthero
2020-11-23 22:44:51

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


spdegabrielle
2020-11-23 22:46:36

> 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



spdegabrielle
2020-11-23 23:28:41

matthew.smith16
2020-11-23 23:33:04

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


sorawee
2020-11-23 23:47:40

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


phanthero
2020-11-24 00:16:26

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


kellysmith12.21
2020-11-24 00:45:26

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


samdphillips
2020-11-24 00:50:39

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


samdphillips
2020-11-24 00:51:22

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


samdphillips
2020-11-24 00:52:25

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


gknauth
2020-11-24 01:03:06

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



samth
2020-11-24 01:43:52

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


samth
2020-11-24 01:46:05

badkins
2020-11-24 01:58:22

wanpeebaw
2020-11-24 02:02:17

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!


camoy
2020-11-24 03:38:53

kellysmith12.21
2020-11-24 04:51:17

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


camoy
2020-11-24 04:57:33

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