
@lexi.lambda Just to make sure it’s not an installation issue, what does raco pkg show --rx drracket
report?

Hello Racketers ! If (define (my-func a b) (+ a b))
then is it possible to get '(lambda (a b) (+ a b))
out of my-func
somehow? i.e. does a function f
exist such that (f my-func)
returns '(lambda (a b) (+ a b))
?

@mflatt $ raco pkg show -l --rx drracket
Installation-wide:
Package[*=auto] Checksum Source
drracket* eafd3e7f353692693402bae51ed0e2f1d7a9c4cc (catalog "drracket" "<git://github.com/racket/drracket/?path=drracket>")
drracket-plugin-lib* eafd3e7f353692693402bae51ed0e2f1d7a9c4cc (catalog "drracket-plugin-lib" "<git://github.com/racket/drracket/?path=drracket-plugin-lib>")
drracket-tool-doc* eafd3e7f353692693402bae51ed0e2f1d7a9c4cc (catalog "drracket-tool-doc" "<git://github.com/racket/drracket/?path=drracket-tool-doc>")
drracket-tool-lib* eafd3e7f353692693402bae51ed0e2f1d7a9c4cc (catalog "drracket-tool-lib" "<git://github.com/racket/drracket/?path=drracket-tool-lib>")
User-specific for installation "development":
[none]

Does the problem persist if you delete “doc/docindex.sqlite” and run raco setup
again?

@contact If you mean that literal list, then no. The source code for functions is not kept around at runtime.

@lexi.lambda Yes, it is what I meant. Thank you!

@mflatt Yes, it persists.

Can you show the first few lines of raco setup
output — the part before the “— updating info-domain tables —” section?

I was wondering whether it should show unexpected collection or link paths, but maybe the issue is multiple links installed, in which case raco link -l \| grep drracket
might be more inetersting.

@mflatt $ raco setup
raco setup: version: 7.1.0.2
raco setup: platform: x86_64-macosx [3m]
raco setup: installation name: development
raco setup: variants: 3m
raco setup: main collects: /Users/alexis/gits/racket/racket/racket/collects
raco setup: collects paths:
raco setup: /Users/alexis/Library/Racket/development/collects
raco setup: /Users/alexis/gits/racket/racket/racket/collects
raco setup: main pkgs: /Users/alexis/gits/racket/racket/racket/share/pkgs
raco setup: pkgs paths:
raco setup: /Users/alexis/gits/racket/racket/racket/share/pkgs
raco setup: /Users/alexis/Library/Racket/development/pkgs
raco setup: links files:
raco setup: /Users/alexis/gits/racket/racket/racket/share/links.rktd
raco setup: /Users/alexis/Library/Racket/development/links.rktd
raco setup: main docs: /Users/alexis/gits/racket/racket/racket/doc
raco setup: --- updating info-domain tables ---

Also: $ raco link -l \| grep drracket
root path: "/Users/alexis/gits/racket/racket/racket/share/pkgs/drracket"
root path: "/Users/alexis/gits/racket/racket/racket/share/pkgs/drracket-plugin-lib"
root path: "/Users/alexis/gits/racket/racket/racket/share/pkgs/drracket-tool-lib"
root path: "/Users/alexis/gits/racket/racket/racket/share/pkgs/drracket-tool-doc"

Well, I’m stumped.

I could try blowing everything I have away and starting from scratch, but I actually already did something extremely close to doing that: doing git clean -fxd
from inside the main racket repo (which did not fix the problem). I could also try destroying ~/Library/Racket/development/, but I don’t know what else could possibly be influencing things.

The only piece of potential weirdness in the environment is that I have PLTCOMPILEDROOTS=compiled/@(version):
, but I don’t feel like that should be causing trouble here, especially not since I deleted all my compiled files when I did git clean -fxd
and started over.

@soegaard2 Hey, can we talk about urlang
? I’m considering making some improvements to it and I have some questions while reading your code. 1. What do import
and export
do exactly? 2. I’d like to make it so that urlang doesn’t generate files by default, but returns javascript as a plain string (so that you can open an (urlang)
macro anywhere and get a compiled javascript string back). Do you mind making this behavior default? 3. I’d like to generate javascript “function-style” modules, so that each generated file creates only one binding in the global scope. Example: const myModule = (function(/* import as ... */){
/* everything here is private */
return { /* exports go here */ };
})(/* imports */);
I thought making an import/export system would be perfect for that. But urlang seems to already feature some kind of import/export stuff, alas different (hence my first question). Do you have any advice on how to make that possible? 4. Last question. Are you currently available to work on urlang, is it fresh in your mind, and if not, do you mind passing over some knowledge (what is WIP, what is OK, what is left to do) so that I can improve it? Thanks! (maybe I should have made an email or a new channel…)

@jerome.martin.dev hi

Import and export is a first step for modules in JavaScript.

They are NodeJS style modules.

oh, ok

So importing modules defined in NodeJS ought to work.

There are tools that convert NodeJS modules to something that works in the browser.


Yeah, I was considering using urlang as a generator for the browser directly

Having a compile time configuration option to switch between NodeJS and Browser modules would be a good thing.

that’s what I had in mind :slightly_smiling_face:

I can remember I have thought about it - but I can’t remember whether I actually implemented anything. We can check the code though.

well, the code looks a bit tied to the nodejs way right now

I am available in the sense, that I’d be happy to answer questions on Urlang.

that’s perfect :slightly_smiling_face:

Devoting large amounts of hacking time will probably need to wait for holidays.

obviously

I was wondering if the code was made a long time ago, or if you worked recently on this

so that I don’t bother you with some old stuff :stuck_out_tongue:

Most of the code is 1–2 years old. But it isn’t abandoned :slightly_smiling_face:

cool !

Next school year I am taking a sabatical and intend to use Urlang to build an interactive math web-site.

on my side I’d like to build websites using racket for the web, for building the server and the front applications, so everything that can improve the coding experience is welcome in my toolbox

If you want to see how modules are implemented currently, see


yes, that’s where it got a bit hairy :stuck_out_tongue:

Let’s back up a bit. You asked about what import and export does.

When Urlang compiles from Urlang to JavaScript, it will throw an “undefined identifier” error, if it meets an undefined identifier.

Therefore if you need to use an identifier provided by the browser, you need to “import” it in order for Urlang not to complain.

I see

So for example, if you are using jquery which uses the identifier $ a lot,

you will need to add an (import $) to tell Urlang that the identifier is defined.

Likewise use (import Math) if you need to use, say, Math.sin()

ok, then my issue is more about the fact that files are generated at compile time, it prevents me from using urlang as a runtime generator

my first goal would be to separate the file generation logic from the rest of urlang

When you say runtime here - do you refer to when the JavaScript runs in the browser?

nope, I’m talking about the racket server runtime

let’s say my server answers to a request on a url, and provides back HTML content

I want javascript to be generated and inserted into the HTML content as well

Okay - that can definitely be solved. Let me think a bit.

I think Urlang already is doing what you want?

well, right now I encapsulated urlang in a javascript
macro like so: (define-simple-macro
(javascript jsexpr ...)
(let ([js (open-output-string)])
(parameterize ([current-urlang-run? #f]
[current-urlang-echo? #t]
[current-output-port js])
(urlang
(urmodule jsmodule jsexpr ...)))
(get-output-string js)))

but I still get exports.js files created in the root of my server…

Okay. Better control over generated files.

I think there is a parameter somewhere…

last time I checked the source, urlang was generating the exports with no conditions

current-urlang-output-file, current-urlang-output-file and current-urlang-exports-file

The docs aren’t exactly complete.


if current-urlang-exports-file
is set to #f
, it’ll generate the file nonetheless

I guess it’s easy to fix

but I wanted your advice before doing so :slightly_smiling_face:

I think that’s on purpose, since line 2287 reads:

(define exports-path (or (current-urlang-exports-file) ; parameter can override (urmodule-name->exports-file-name name)))

yes

But the idea to have an ’dont-generate-exports is a good idea.

good, I’ll make a PR then?

perhaps a new parameter: current-generate-exports?

yes, make an PR

So far the primary goal of Urlang was to generate code that can run in NodeJS. Therefore the “direct to browser” story can definitely be improved.

I’d be glad to help doing so :slightly_smiling_face:

The idea behind generating NodeJS code is, that it makes testing easier during development.

Running the generated JavaScript and seeing result in DrRacket is a great time saver.

Btw when you modify main.rkt it’s important to regenerate bytecode files. Otherwise you will get a performance hit when you use it afterwards.

mmmh, you mean using raco
?

yes

I didn’t know there were performance issues, I thought racket generated .zo files

If everything runs fine, then don’t worry.

If you suddenly find yourself waiting an unreasonably time, try runnin raco setup manually.

ok!

The urlang compiler itself is fast enough - but the generating the compiler using nanopass can be slow.

btw I think you forgot to uncomment the lang line in ffi.rkt

got an error with that, but I guess it’s ok without that file

huh - you are right

I thought I fixed that recently.

yeah, I saw your last commit :stuck_out_tongue:

you fixed it in colors.rkt but not in ffi.rkt

ah

fixed

oh, last thing

there’s only a (var [a 42])
syntax, but in ES6 there’s const and let

Yes. Right now the target is ES5. However let is available in extras.rkt (I think)


const is not available

I don’t see new
though

Hmm. I misremembered. The let expression is builtin:

(let ((x <expr>) …) <statement> … <expr>)


Remind me, what does new do?

it creates a new instance from a function


It’s there since JS1

That needs to be added. Will you make a PR?

sure!

I’ll try to do all that tomorrow or this weekend, it’s getting late around here :slightly_smiling_face:

Same here.

I guess we’re on the same time zone

I think so.

glad to see some europeans around here :stuck_out_tongue:

thanks for the time you accorded me!

always happy to chat about Urlang

:slightly_smiling_face:

see you around!

@christopher.milton has joined the channel