pocmatos
2018-3-19 11:28:39

I am attempting to write a macro that loads a file whose path is stored in an environment variable. The macro seems to expand to the right thing… but the provided names seem not to be available. This might have to do with how phases work and I am not completely clear on how to get that to work. The macro is simple enough: (define-syntax (require/from-env stx) (syntax-parse stx [(_ v:str) (with-syntax ([mod-name (getenv (syntax->datum #'v))]) #'(require mod-name))])) and yet if you try to use this to require a module which provides a variable name, after (require/from-env "NAME") where export NAME=name.rkt, name is still not defined. Any suggestions on how to get something like this to work?


ryanc
2018-3-19 13:12:18

@pocmatos require is an unhygienic binding form. It introduces names based on, in this case, the scopes on the mod-name syntax. Try wrapping the result of get-env with (datum->syntax #'v _ #'v). (Or instead of #'v, you could use stx. Both should work if you use the macro directly; but they are different if you have macros expanding into require/from-env uses.)


pocmatos
2018-3-19 13:14:54

@ryanc Thanks for the clarification, however I remaining confused. Why is this different from what conditional-require does <https://docs.racket-lang.org/syntax-parse-example/index.html?q=conditional-require#%28part._conditional-require%29> ?


pocmatos
2018-3-19 13:16:29

by wrapping you mean [mod-name (datum-&gt;syntax stx (getenv (syntax-&gt;datum #'v)) #'v)]?


ryanc
2018-3-19 13:18:01

@pocmatos conditional-require just passes one of its arguments through, so the thing being required has the scopes of the macro use. In contrast, require/from-env is creating a new syntax object, and by default it gets a scope marking it as originating from your macro.


pocmatos
2018-3-19 13:18:07

I understand why it is unhygienic because it inserts new bindings based on what the required file provides. However, this is surely possible somehow and I cannot understand how it’s different from conditional-require. I haven’t actually tested conditional-require although I assumed it works.


pocmatos
2018-3-19 13:18:34

humm… let me process that message…


ryanc
2018-3-19 13:19:59

Yes, that wrapping should work.


pocmatos
2018-3-19 13:20:54

by scope, do you mean namespace? are they interchangeable?


pocmatos
2018-3-19 13:21:17

ah, the datum-&gt;syntax stx... part ensures the scope is the same as the scope of the macro?


pocmatos
2018-3-19 13:22:08

@ryanc there is a huge amount of information on scopes, phases, namespaces out there. Which one should I look at to understand what is happening with scopes? Any suggestions?


pocmatos
2018-3-19 13:25:20

I can however confirm that your suggestion works but it still feels like magic to me.


ryanc
2018-3-19 13:31:26

sorry, right now I don’t have all the sources paged in well enough to make a recommendation


ryanc
2018-3-19 13:31:56

I hope the rest of channel has some opinions, though


pocmatos
2018-3-19 13:36:04

@ryanc sure, thanks.


abmclin
2018-3-19 14:52:42

@pocmatos Matthew Flatt’s report about the set of scopes binding model for macro expansion may be helpful http://www.cs.utah.edu/plt/scope-sets/


samth
2018-3-19 15:25:45

Scope and namespace are not the same thing


jerome.martin.dev
2018-3-19 15:47:39

@pocmatos the datum-&gt;syntax ensures mod-name is a syntax that can be pushed into the final expression, and not a value for the syntax phase.


jerome.martin.dev
2018-3-19 15:50:05

I guess you could also try dynamic-require if you don’t directly care about performance. You usually write a macro to prevent something from being calculated at run time, but most of the time it’s premature optimization and a good old function just works.


pocmatos
2018-3-19 16:00:02

@jerome.martin.dev Tried dynamic require already. Takes 20secs on a performance bounce app. Really need compile time dynamic require.


pocmatos
2018-3-19 16:00:27

Performance bound. Not performance bounce. :slightly_smiling_face:


jerome.martin.dev
2018-3-19 16:06:17

Makes sense then :wink:


jerome.martin.dev
2018-3-19 16:13:04

So, I made this cond/list macro that builds a list with a condition for each element. Right now it uses when and set! then returns the result. I got some questions: 1. Does this macro already exist somewhere? 2. Do you think of a better way to write this? 3. Is my approach correct?


samth
2018-3-19 16:14:54

If dynamic-require takes 20 seconds then probably you should run raco make on that file first


ryanc
2018-3-19 16:17:58

@jerome.martin.dev how about (append (if mc.condition (list mc.value) null) ...)? Or (let* ([result null] [result (if mc.condition (cons mc.value result) result)] ...) (reverse result))? I would avoid set! unless it’s truly necessary.


jerome.martin.dev
2018-3-19 16:18:48

@ryanc does null disappear from the list ?


pocmatos
2018-3-19 16:19:08

@samth raco make can’t do anything afaict if the choice of lib to require is done at runtime. Moving it to a compile time require and a raco make seems to help.


samth
2018-3-19 16:19:55

You want to ensure that whatever library you are calling dynamic-require on is compiled ahead of time


pocmatos
2018-3-19 16:20:47

Will give it a go and benchmark some alternatives.


pocmatos
2018-3-19 16:21:20

To raco make a library, it’s enough to call raco make on all rkt files belonging to the library, right?


ryanc
2018-3-19 16:21:43

@jerome.martin.dev yes: (append (list 1) null (list 3)) = (list 1 3)


jerome.martin.dev
2018-3-19 16:21:43

@ryanc oh wait I got it null is the empty list x)


ryanc
2018-3-19 16:22:24

@jerome.martin.dev yes; you can use '() if you prefer


jerome.martin.dev
2018-3-19 16:22:25

I always write '(), I forgot null was equivalent


jerome.martin.dev
2018-3-19 16:22:54

this is definitely better, thanks!


jerome.martin.dev
2018-3-19 16:28:44

it never came to me that you could use let* to modify the same value multiple times, thanks for pointing me that.


ryanc
2018-3-19 16:34:50

@jerome.martin.dev to nitpick, there’s no modification going on. The macro creates a sequence of bindings of the same name, each one shadowing the last. But use shadowing carefully; it actually does have some of the headaches of set!: instead of different values at different points in time, you have to worry about different values at different shadowing levels.


jerome.martin.dev
2018-3-19 16:35:16

oh, I see


jerome.martin.dev
2018-3-19 16:35:52

I guess the compiler handles that, at least in the context of this macro


jerome.martin.dev
2018-3-19 16:36:39

some kind of “discard all the unused shadows” going on


ryanc
2018-3-19 16:38:31

compilers typically rename all local variables to have distinct names to simplify their work


ryanc
2018-3-19 16:40:41

Actually, the Racket macro expander does that too. When it sees a local variable binding, it creates a new “variable identity” for it. It just doesn’t change the symbol.


samth
2018-3-19 16:41:07

@pocmatos raco make follows dependencies, so you just need to use it on the particular modules that might be used in dynamic-require


pocmatos
2018-3-19 16:58:43

@samth will try. Thinking about it now, the time taken by the 20 might be due to unit linking, not necessarily requiring them. Have to measure.


pocmatos
2018-3-19 16:59:50

Using units has they allow to easily share public interfaces without sharing internal details. A bit like shared library files (units) and include files (sigs). Have found no better way to do this in racket.


pocmatos
2018-3-19 17:00:34

Argh, apologies for the typos, writing this on my phone.


leafac
2018-3-19 17:24:51

Today I Learned

The Redex documentation has this to say about the ‘term’ form: “Symbols in a term whose names end in guillemets (French quotes) around a number (for example asdf«5000») will be modified to contain a smiley face character (for example asdf«5000:relaxed:»). This is to prevent collisions with names generated by the freshening process that binding forms use.” But what if the term ends in guillemets around a number with a smiley face?

#lang racket
(require redex)
(term a«1») ;; =&gt; 'a«1☺»
(term a«1☺») ;; =&gt; 'a«1☹»
(term a«1☹») ;; =&gt; 'a«1☹☺»
(term a«1☹☺») ;; =&gt; 'a«1☹☹»
(term a«1☹☹») ;; =&gt; 'a«1☹☺☺»

Binary counting with smiley and frowning faces. That is clever. Redex is clever.


leif
2018-3-19 17:28:09

Does anyone have any recommendations for alternatives to DrRacket for someone who is new to programming?


leif
2018-3-19 17:28:30

Asking someone new to set up emacs and racket-mode on their own seems like a bit…much…to me.


abmclin
2018-3-19 17:45:38

How about just plain notepad or notepad++?


jerome.martin.dev
2018-3-19 17:45:46

IMHO, DrRacket is the best I can think of because it embeds an interactive editor and a REPL with a big RUN button, and visual results for images or graphics. But I guess any user-friendly editor like SublimeText (alas not FOSS) or Notepad-like software are good, as long as you can open a terminal in another window and show how to run racket my-program.rkt.


jerome.martin.dev
2018-3-19 17:50:10

I definitely did my first program on notepad when I was 11yo, writing html, saving the file, and double-clicking on it to see the result. (sorry I’m fairly young, but I did use floppy disks to save my work, don’t judge me :P)


jerome.martin.dev
2018-3-19 17:52:56

Anything that triggers the “edit > see result > adapt” loop, in a graphic way, is good to take. @leif What kind of audience is it for?


jerome.martin.dev
2018-3-19 17:57:33

I found that some people are more at ease with imperative languages and infix notation because they have a mathematical background of thinking about stuff equal to other stuff. They feel at home writing "fruits = 5". I usually push them to Python. For people that are more at ease with words instead of symbols, I push them to Racket because it feels like writing a story, and you can use whatever identifiers you like, there are no syntax rules apart from s-exps.


spdegabrielle
2018-3-19 17:58:07

I started a thread by ‘Alternatives to DrRacket’ on 26-nov–17 There were even some suggestions that were not Emacs. :grinning: [I was trolling for DrRacket development ideas- I settled on doing a navigation bar but that is currently in the spaghetti code phase of development:sob:]


leif
2018-3-19 18:00:08

I’m looking for something that allows someone to learn programming with Racket, possiblyusing the HTDP student languages.


jerome.martin.dev
2018-3-19 18:00:10

For me the biggest issue that prevents me from using DrRacket in my daily programming is that I can’t open a folder in a sidebar, and see all the files in it, calling that a “project” in which I can easily navigate.


leif
2018-3-19 18:00:27

Unfortunately DrRacket is a non-starter because it doesn’t work at all with screen readers.


jerome.martin.dev
2018-3-19 18:00:40

oh ok


jerome.martin.dev
2018-3-19 18:00:55

I think emacs has a good screen reader


leif
2018-3-19 18:01:07

And it will take some time (and probably some api enhancements I will need to clear with @mflatt) before I will be able to get drracket to work with them.


jerome.martin.dev
2018-3-19 18:01:11

but it’s hard to configure (as always…)


leif
2018-3-19 18:01:34

Ya, emacs does have one. But ya, since this person is new, I feel kind of bad just dumping them in emacs, ya know?


jerome.martin.dev
2018-3-19 18:01:43

Yes x)


leif
2018-3-19 18:02:19

Alrigh, no idea then?


jerome.martin.dev
2018-3-19 18:04:28

Once I tried configuring my environment so that I could code without a screen. It appears to be extremely difficult, and the open source community of blind people is sparse. Proprietary software is still the rule here.


ryanc
2018-3-19 18:05:55

Maybe try Pyret or WeScheme (?). I would guess that things that run in web browsers would be most likely to work with screen readers (but I don’t know firsthand).


leif
2018-3-19 18:06:43

@jerome.martin.dev I mean, NVDA is fine. Its honestly just the fact that DrRacket is a giant snip%, and the snip GUI layer doesn’t support screen reader. :disappointed:


jerome.martin.dev
2018-3-19 18:06:50

@ryanc Yes, web browsers are well supported by most screen reading solutions, and web technology is easier to configure for disabled people.


leif
2018-3-19 18:07:32

@ryan I guess pyret would work. Wescheme seems to support some scheme like constructs, but there doesn’t seem to be any way to set the #lang.


leif
2018-3-19 18:07:51

But yes, web browsers are a good approach.


ryanc
2018-3-19 18:10:36

You could also use iracket with jupyter, but it also doesn’t have an easy way to change the #lang (although you might be able to clone and adapt kernels for the HtDP languages). It also has all of the drawbacks of the top level and then some (re out of sync definitions).


leif
2018-3-19 18:11:47

Mmmm…okay.


leif
2018-3-19 18:12:15

Well I’ll suggest wescheme or pirate first. Hopefully one of those will work. :slightly_smiling_face:


jerome.martin.dev
2018-3-19 18:15:32

It looks like WeScheme is locking the keyboard in its text editor though, I can’t escape once I have focus on it.


jerome.martin.dev
2018-3-19 18:16:24

Oh, you can change focus with F6


samth
2018-3-19 18:20:54

@samth set the channel topic: Sign up for Racket School! https://news.ycombinator.com/newest — Racket — http://racket-lang.orghttp://pasterack.org - Slack invite link: http://racket-slack.herokuapp.com - Archives: http://racket.slackarchive.io/


leif
2018-3-19 18:21:00

Hmm…I’ll have to try it with other screen readers in a bit. Thanks for the heds up


samth
2018-3-19 18:21:25

Everyone, check out Racket School 2018: https://summer-school.racket-lang.org/2018/


samth
2018-3-19 18:21:34

@samth set the channel topic: Sign up for Racket School! https://summer-school.racket-lang.org/2018/ — Racket — http://racket-lang.orghttp://pasterack.org - Slack invite link: http://racket-slack.herokuapp.com - Archives: http://racket.slackarchive.io/


jerome.martin.dev
2018-3-19 18:23:49

@samth will it be recorded?


samth
2018-3-19 18:24:04

I don’t know, but I don’t think that’s planned


pnwamk
2018-3-19 18:46:26

scribble+redex picts — I’ve got a large html document with lots of redex figures/terms and I’m getting large number of duplicate .png’s generated for rendered terms that I frequently mention in the text (e.g. τ). I tried manually caching the picts instead of directly using render-term (i.e. don’t render the same redex term more than once) and that didn’t seem to help. Is this just a general scribble/html issue (i.e. that it generates a .png for every occurrence of a pict)?


githree
2018-3-19 19:33:19

@leif VS Code has nice accessibility story: https://code.visualstudio.com/docs/editor/accessibility


ben
2018-3-19 19:35:24

sounds like a scribble issue


leif
2018-3-19 19:38:45

@githree Oh cool. Does VSCode also have a good Racket story?


githree
2018-3-19 19:39:31

For beginners I believe it should work just fine


githree
2018-3-19 19:39:40

some extensions:




githree
2018-3-19 19:41:01

VS Code is definitely much easier to set up than emacs


githree
2018-3-19 19:41:10

especially for beginners


leif
2018-3-19 19:42:02

OMG, thank you so much.


githree
2018-3-19 19:43:13

you’re welcome


jerome.martin.dev
2018-3-19 20:21:38

That’s a nice catch, I didn’t thought about VSCode. There’s an issue with the access to the menu though, due to a bug in electron (https://github.com/electron/electron/issues/2504) that prevents users from accessing the menu using the ALT key and moving around with ← and →.


jerome.martin.dev
2018-3-19 20:22:36

You need to check if that’s an issue.


blerner
2018-3-19 20:24:57

@leif Pyret (specifically http://code.pyret.org\|code.pyret.org) should work well with screen readers, and I believe we have further screen-reader-friendliness coming in a PR soon. please feel free to file bugs if it doesn’t work for you :slightly_smiling_face:


leif
2018-3-19 21:19:02

@blerner Oh cool. Thanks.


mflatt
2018-3-19 21:31:28

If I remember correctly, Scribble should only use one copy of a byte-equivalent file. Is it that the files are not byte-equivalent, or that the intended merging doesn’t work?