sorawee
2018-11-15 10:21:32

Is there an easy way to extend an arbitrary language? For example, I want to extend #lang pollen with my own #%top. What’s the best way to accomplish that?

I’m following http://blog.racket-lang.org/2017/03/languages-as-dotfiles.html, but the problem is that the blog post assumes that something like scribble/reader exists. I don’t think that kind of thing exists for pollen.


soegaard2
2018-11-15 14:27:09

This is a bit off-topic, but since this group probably will appreciate an example of how things can blow up, when scope rules are unclear, I’ll post it anyways. Note that the blue graph of a(x) has a local minimum at x=2.8, but the red graph of a’(x) doesn’t cross the x-axis at x=2.8.


jerome.martin.dev
2018-11-15 14:39:31

I guess it’s because the right answer may be 1.1835, which seems more likely to be crossed on the graph (but it looks more like 1.8 or something.. weird)


jerome.martin.dev
2018-11-15 14:40:48

I remember in math class being told that you can toss out irrelevant results somehow when you get multiple answers like that.


samth
2018-11-15 14:46:30

@sorawee you can make a module which does (require (all-from-except pollen #%top)) (provide (all-from-out pollen))


sorawee
2018-11-15 15:20:25

@samth You mean except-in? . As I understand all-from-except is for #%provide.

Would you mind telling me exactly what I should put in my-pollen/main.rkt? Let’s not even care about overriding #%top. Here are my attempts that failed:

#lang racket/base

(require pollen)
(provide (all-from-out pollen))

fails on the program

#lang my-pollen
abc

because of the error collection not found for module path: my-pollen/lang/reader.

So I do need to create a reader.

#lang racket/base

(require pollen)
(provide (all-from-out pollen))

(module* reader syntax/module-reader
  my-pollen
  #:read p:read
  #:read-syntax p:read-syntax
  (require (prefix-in p: pollen)))

fails because p:read-syntax is unbound.


samth
2018-11-15 15:21:03

you probably need to require whatever provides pollen’s read-syntax etc


samth
2018-11-15 15:21:11

which i guess isn’t pollen


samth
2018-11-15 15:22:17

you could probably do the same thing that pollen does, which is: (module reader "private/reader-base.rkt" default-mode-auto)


samth
2018-11-15 15:22:30

of course you’d need to change that language to pollen/private/reader-base


soegaard2
2018-11-15 15:23:00

@jerome.martin.dev The problem is that the x in the definition of y has global scope, but in am(x) the differentiation happens with respect to a “local x”. If one enter am(z) then the result returned is 1/(x–2)+3 (nope that’s not a typo). am(z) = d/dz( am(z) ) = d/dz ( z*y) = y = 1/(x–2)+3. Sigh.


jerome.martin.dev
2018-11-15 15:24:07

oh


sorawee
2018-11-15 15:24:26

Thanks! This works :slightly_smiling_face:


jerome.martin.dev
2018-11-15 15:24:57

so that’s definitely a programming issue :stuck_out_tongue:


jerome.martin.dev
2018-11-15 15:25:17

maths are always right, it’s what they say


soegaard2
2018-11-15 15:34:34

It’s not exactly easy to explain in a high school math class …


soegaard2
2018-11-15 15:34:48

That x is not always x.


tealeg
2018-11-15 15:39:20

First teach them about Gödel, and then it’ll all be clear :troll:


jerome.martin.dev
2018-11-15 15:39:23

I think it’s the study they did at MIT: They asked their students at the beginning of classes something like: a = 10; b = 20; a = b; What is the value of a and b? About 40% got it right, the others did not understand. Then at the end of the semester, they ask the same question again, and get… exactly the same results.


jerome.martin.dev
2018-11-15 15:40:16

I don’t remember if it was MIT or Harvard, or some other big uni


jerome.martin.dev
2018-11-15 15:41:57

They realized two things: a lot of people are not good at “doing the computer in their heads”, and that maybe the way they teach IT was not that good to begin with


jerome.martin.dev
2018-11-15 15:45:41

I think the fact that we tend to program with this idea of a state machine in our head is also part of the problem. We were told the correct result was that “a becomes the value of b”. But in declarative or functional languages, the answer “error: illegal equality” might be perfectly acceptable.


jerome.martin.dev
2018-11-15 15:49:15

so in the end, the people who answer “I don’t know” or “It’s impossible” are as legitimate as the 40% who answer “a = b = 20”


jerome.martin.dev
2018-11-15 15:52:29

The state machine is only a limit from the Turing/Von Neumann architecture we use as computers. Mathematics don’t care about that and can have x be whatever the reader has in her mind.


jerome.martin.dev
2018-11-15 15:54:03

But i think I’m slowly losing track there.. I’ll see myself out and leave you dealing with the philosophical repercussions :stuck_out_tongue:


popa.bogdanp
2018-11-15 16:12:18

jerome.martin.dev
2018-11-15 16:33:07

Yes, thanks for bringing the reference!



jerome.martin.dev
2018-11-15 16:54:51

@sorawee No, but I’m definitely reading this right now!


lexi.lambda
2018-11-15 19:40:09

Is there a way to change what object-name produces on classes, similar to how procedure-rename works on procedures?


leif
2018-11-15 19:58:08

@robby The documentation for front-end/finished-complete-program says: “It must return without raising an error, or else the DrRacket window will be wedged.”


leif
2018-11-15 19:58:21

What does it mean fo a window to be wedged?


robby
2018-11-15 19:58:32

Generic badness


robby
2018-11-15 19:59:04

Undefined behavior


robby
2018-11-15 19:59:34

(But highly likely to be unresponsive and highly unlikely to produce nasal demons)


leif
2018-11-15 19:59:50

Ah, okay, thanks. :slightly_smiling_face:


leif
2018-11-15 20:00:08

Out of pure curiosity, did you choose that word, or is it a term from somewhere else?


leif
2018-11-15 20:00:25

(I couldn’t find it after a quick search, but I could be searching for the wrong thing. :wink: )


robby
2018-11-15 20:01:04

Dunno


robby
2018-11-15 20:01:17

That’s what it means to me


leif
2018-11-15 20:03:04

lol…thanks. :slightly_smiling_face:


ben
2018-11-15 20:03:36

hmm … american heritage dictionary says: (1) having the shape of a wedge; thick at one end tapered at another (2) stuck; jammed


ben
2018-11-15 20:06:59

@leif maybe the docs should say “If this method raises an exception, the behavior of the DrRacket window is undefined.”


leif
2018-11-15 20:08:15

Mmm….maybe? Although honestly, now that robby explained it to me, wedged seems pretty accurate here.


leif
2018-11-15 20:08:41

Although I would probably say, the behavior is undefined, but likely the window will be frozen.


leif
2018-11-15 20:08:44

Or something like that?


robby
2018-11-15 20:08:48

I think it would be good to keep the more specific meaning


robby
2018-11-15 20:09:00

Probalby my use of undefined is because I’m watching jesse type C++ code :slightly_smiling_face:


leif
2018-11-15 20:09:03

Agreed.


robby
2018-11-15 20:09:05

happy to use a different word


samth
2018-11-15 20:09:07

“wedged” is pretty common for this situation in my experience


robby
2018-11-15 20:09:16

it’s a fun word :slightly_smiling_face:


leif
2018-11-15 20:09:49

@samth Interesting, may I ask where?


leif
2018-11-15 20:09:57

(Also I 100% agree, the word is pretty awesome.)


ben
2018-11-15 20:10:01

ok (I was confused by wedged)


leif
2018-11-15 20:10:17

I’ve heard unresponsive, frozen, stuck, but this is the first time I’ve heard of wedged. :smile:


samth
2018-11-15 20:10:27

for example, it’s used here: https://en.wikipedia.org/wiki/Hang_(computing)


leif
2018-11-15 20:11:03

Ah, okay.


leif
2018-11-15 20:11:25

So its a cooperative multitasking specific term.


leif
2018-11-15 20:11:33

That makes a lot of sense. Thanks @samth


leif
2018-11-15 20:14:43

@robby & @samth (@ben just suggested that we add a margin note linking or explaining the definition of wedged, since its apparently fallen out of modern parlance. Would you be opposed to that?)


leif
2018-11-15 20:15:14

Personally I am 100% on side wedged here. But I also think linking to a definition isn’t a bad idea. :slightly_smiling_face:


robby
2018-11-15 20:15:17

I don’t think this word is that unknown


robby
2018-11-15 20:15:25

and if it were, we should change it


robby
2018-11-15 20:15:43

I don’t think it is in common usage for people in general, but I think it is for people who work with computers that get wedged a lot


robby
2018-11-15 20:15:43

:slightly_smiling_face:


leif
2018-11-15 20:16:01

FWIW, I asked about 10 people in physical space (in and around the PL labs), and none of us had heard the term before. :slightly_smiling_face:


leif
2018-11-15 20:16:39

But, I could have easily just asked the wrong 10 people. :slightly_smiling_face:


blerner
2018-11-15 20:27:32

I mean, I’ve certainly used it in this context, often


lexi.lambda
2018-11-15 20:27:33

FWIW, I didn’t have trouble inferring the meaning of the word “wedged” in a computing context since I was familiar with it in a non-computing context, such as “the door is wedged”. But maybe that isn’t a common use.


abmclin
2018-11-15 21:45:29

While I also inferred the general meaning of the word, I had never heard of it used in computer science context. I found it enlightening that the more nuanced meaning is related to cooperative multitasking which makes sense since it is dependent on tasks behaving cooperatively and keeping things moving smoothly without capturing and holding on the control of the machine.


nathaniel
2018-11-16 00:56:14

Hello! :wave: There doesn’t seem to be a Pollen-specific channel, so I’ll ask here: I’ve been building a multilingual website using Pollen, and haven’t figured out a good method to “isolate” or “separate” pagetrees by language. For example, I’d like to be able to say:

#lang pollen

about.html
◊foo.html{
    bar.html
    baz.html
    etc.html
}

--- separator ---

accueil.html
◊foo.html{
    bar.html
    baz.html
    etc.html
}

For now my solution has been to organize each language as it’s own pollen document. This works, but it’s really repetitive and seems like overkill. If anyone has ideas or knows of simpler ways to do this, I’d be very thankful to hear them. I am new to Racket and really having fun, thanks to everyone involved developing and supporting it!


sorawee
2018-11-16 04:34:58

I’m building a multilingual website using Pollen too! (English and Thai)

Here’s my idea: use only one file per one document, but for each document, do something like this:

@english{<my english content here>}
@thai{<my thai content here>}

@english and @thai should create a div with an identifiable class/id.

Then in the template, include a JavaScript that hides one language (sth like document.getElementById('thai-lang').style.display = "none";). And then there might be a button that lets you switch a language, etc. It’s totally up to you how you want to design this.