
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?

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

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

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

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

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.

humm… let me process that message…

Yes, that wrapping should work.

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

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

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

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

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

I hope the rest of channel has some opinions, though

@ryanc sure, thanks.

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

Scope and namespace are not the same thing

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

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.

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

Performance bound. Not performance bounce. :slightly_smiling_face:

Makes sense then :wink:

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?

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

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

@ryanc does null
disappear from the list ?

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

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

Will give it a go and benchmark some alternatives.

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

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

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

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

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

this is definitely better, thanks!

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

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

oh, I see

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

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

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

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.

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

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

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.

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

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») ;; => 'a«1☺»
(term a«1☺») ;; => 'a«1☹»
(term a«1☹») ;; => 'a«1☹☺»
(term a«1☹☺») ;; => 'a«1☹☹»
(term a«1☹☹») ;; => 'a«1☹☺☺»
Binary counting with smiley and frowning faces. That is clever. Redex is clever.

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

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

How about just plain notepad or notepad++?

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
.

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)

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?

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.

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:]

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

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.

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

oh ok

I think emacs has a good screen reader

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.

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

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

Yes x)

Alrigh, no idea then?

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.

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

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

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

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

But yes, web browsers are a good approach.

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

Mmmm…okay.

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

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

Oh, you can change focus with F6

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

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

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

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

@samth will it be recorded?

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

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

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

sounds like a scribble issue

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

For beginners I believe it should work just fine

some extensions:



VS Code is definitely much easier to set up than emacs

especially for beginners

OMG, thank you so much.

you’re welcome

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

You need to check if that’s an issue.

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

@blerner Oh cool. Thanks.

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?