soegaard / urlang Goto Github PK
View Code? Open in Web Editor NEWUrlang is JavaScript with a sane syntax
Urlang is JavaScript with a sane syntax
Error here: http://pkg-build.racket-lang.org/server/built/fail/urlang.txt
raco setup: --- summary of errors ---
raco setup: error: during making for <pkgs>/urlang/compiler-rjs
raco setup: urmodule-name->exports: exports file not found: "runtime.exports"
raco setup: compiling: <pkgs>/urlang/compiler-rjs/compiler.rkt
raco setup: error: during making for <pkgs>/urlang/compiler-test
raco setup: urmodule-name->exports: exports file not found: "runtime.exports"
raco setup: compiling: <pkgs>/urlang/compiler-rjs/compiler.rkt
raco setup: error: during making for <pkgs>/urlang/urlang-examples/ractive
raco setup: /home/racket/build-pkgs/user/.racket/6.4/pkgs/urlang/urlang-examples/ractive/ractive-original.rkt:10:9: collection not found
raco setup: for module path: html-writing
raco setup: collection: "html-writing"
raco setup: in collection directories:
raco setup: /home/racket/build-pkgs/user/.racket/6.4/collects
raco setup: /home/racket/build-pkgs/racket/collects
raco setup: ... [197 additional linked and package directories]
raco setup: compiling: <pkgs>/urlang/urlang-examples/ractive/ractive-original.rkt
The html-writing
part should be fixed by #2.
I pulled the latest fix, but I think (ref ...) is still broken in some cases.
This doesn't work:
(ref a "b" "c" "d") => a["b"]["b"]["b"];
but it works for other inputs:
(var a b c d) (ref a b c d) => a[b][c][d];
(ref a 0 1 2 3) => a[0][1][2][3];
and the chain works:
(ref (ref (ref a "b") "c") "d") => a["b"]["c"]["d"];
Signal an error when a binary JavaScript operators is used with 0, 1, 3, or more arguments.
Examples:
2<=3<=4 does not work in JavaScript.
(and e) is an error since the JavaScript operator && takes two arguments.
The object literal
(object [foo 1] [foo 2])
will generate {foo: 1, foo:2}. It evaluates to the object {foo: 2}.
A warning saying that the name foo
is used twice would be a good thing.
The following example gives the error α-rename: (urlang) unbound variable in: fn
when it shouldn't.
#lang racket
(require urlang)
;; comment this out and the unbound variable error goes away
(define (fn) "this is causing the problem")
(urlang
(urmodule
test-mod-a
(export fn)
(define (fn)
"hello?"))
(urmodule
test-mod-b
(require test-mod-a)
(fn)))
The issue is caused by the racket definition of fn
. If you comment out the racket binding of fn
, the issue goes away.
I'm not sure exactly why this is happening, but is urlang somehow capturing the racket binding?
While dot identifiers work in reference positions, they don't work in assignment ones:
(define x (object))
(:= x.a 42)
for example throws an error. Obviously I 'could' put the identifier in an import list, but that does seem a bit clunky:
(import x.a)
(define x (object))
(:= x.a 42)
It seems like this syntax does work, but is not documented:
(define x (object))
(:= x "a" 42)
The keyword instanceof
appeared in ES6.
This works
(define (array-intersection ars)
; copy first array
(var [result ((dot (ref ars 0) slice))])
; intersect the remaining arrays with the result array
(for ([a in-array ars]
[j in-naturals 0]) ; (sigh) don't use i here
(when (> j 0)
(:= result (string-array-intersection2 result a))))
result)
But if j
is replaced with i
the macro expansion is wrong.
The expression (and foo)
currently emits "&& foo".
Change it to omit &&.
Even though ~ can be used in an identifier (check this) it can't be used as the first character.
https://stackoverflow.com/questions/1661197/what-characters-are-valid-for-javascript-variable-names
Thus mangle
needs to handle the first character specially.
Originally Urlang targeted ES5.
Now we can target ES6, so Urlang needs to support ES6 (esm) modules.
And (cross fingers) then we can use Skypack for easy import of
modules written in plain JavaScript.
I don't know if you are still working on this, but I've been having fun playing with urlang and came across an error.
This definition in a urmodule:
(define a
(let ()
(var [a (object)])
(:= a "key" "val")
a))
produces:
var a=((function(){var a_1={};(a["key"]="val");return a_1;})());
Identifiers such as foo.bar expand to foo.bar which means foo["bar"].
The identifier foo.bar-baz currently expands to foo.bar-baz but should
be foo["bar-baz"] or perhaps foo.bar_baz.
Note: The dot notation is currently (ab)used to call methods.
Therefore switching to foo["bar"] everywhere in the expansion
will break method calls.
As title says, prevent the build-server of running non-tests.
http://pkg-build.racket-lang.org/server/built/test-fail/urlang.txt
Maybe I'm using urlang incorrectly but I don't know how to produce the following instruction in Javascript:
renderer.view.style.position = "absolute";
I'm trying with:
(:= (dot renderer view style position) "absolute")
but the error suggests that assignments only allow identifiers as the first parameter.
A common JavaScript idiom is to have a function that returns a namespace that includes other functions. This is a convenient way to encapsulate data:
function varray(size, fill) {
...
function dump() { console.dir(data); }
...
return { dump, set, get };
}
When I tried to do this in Urlang:
(define (varray size fill)
...
(define (dump) (console.dir data))
...
(object [dump dump] [set set] [get get]))
It errored out on the interior define
with:
square.rkt:153:8: parse-expr: expected an expression, got #<syntax:square.rkt:153:8 define>
in: define
Thank you!
BTW, for reference, here's what I went with:
(define (varray size fill)
(let* ([size size]
[stride-y (ref size 0)]
[stride-z (* (ref size 0) (ref size 1))]
[locate (λ (x y z) (+ x (* y stride-y) (* z stride-z)))]
[data (Array.from
(object [length (* (ref size 0) (ref size 1) (ref size 2))])
(λ (e i) fill))])
(object [dump (λ () (console.dir data))]
[get (λ (x y z) (ref data (locate x y z)))]
[set (λ (x y z v) (:= data (locate x y z) v))]
)
))
Make sure the SVG example runs with at-expressions.
Newlines needs to be quoted with an .
#lang racket
(require urlang)
(current-urlang-echo? #t)
(current-urlang-run? #t)
(urlang
(urmodule foo
(console.log "b
ar")))
(Working from commit: b6ceb75)
urlang fails to build if the html-parsing
package isn't installed:
raco setup: error: during making for <pkgs>/urlang/urlang/html
raco setup: standard-module-name-resolver: collection not found
raco setup: for module path: html-parsing
raco setup: collection: "html-parsing"
raco setup: in collection directories:
raco setup: /Users/jessealama/Library/Racket/7.1/collects
raco setup: /Applications/Racket v7.1/collects
raco setup: ... [186 additional linked and package directories]
raco setup: compiling: <pkgs>/urlang/urlang/html/to-at-exp.rkt
There are a few more errors like this, all pointing to the absence of html-parsing.
Installing html-parsing
does the job. It's enough to add html-parsing
to build-deps
in info.rkt
.
Hi, I'm playing around with Urlang coming from the Javascript world. My understanding is that is should be possible through macros to create a string (in something like the compile phase) that Urlang would be able to use. Here is my attempt:
(define-syntax m
(syntax-rules ()
[(_) (xexp->html `(html (head (title "Hello world!"))
(body (p "Hey out there!"))))]))
(urlang
(urmodule demo-fact
console.log(m)
))
but it seems it is not evaluating "m" right away as I thought it did. My understanding was that it would literally replace the macro with the result of the expression? How is this achieved?
I am hoping to use Urlang to write code for Gatsby. The Gatsby code examples use ES6 syntax. Gatsby pages and components export modules as default.
Is there a way in Urlang to export modules as default rather than named? I don't see any examples. I'm also inexperienced in both Javascript and Racket, so I may be missing something obvious.
Requiring multiple modules produces javascript that has multiple var MODULE =
instances.
Two modules:
(urlang
(urmodule mod-a
(export a)
(define a 0))
(urmodule mod-b
(export b)
(define b 1)))
And another module requiring both:
(urlang
(urmodule test
(require mod-a)
(require mod-b)))
produces:
"use strict";
var MODULE = require("./mod-b.js");
var b = MODULE["b"];
var MODULE = require("./mod-a.js");
var a = MODULE["a"];
I don't know that this is necessarily a bug or even incorrect code, but some tools don't like it. Rollup (rollupjs.org) for example chokes on it with the error [!] Error: Identifier 'MODULE' has already been declared
.
The spread operator ...
can be used like this:
{...styles, color: "red"}
In Urlang, allow a spread operator at the beginning of an object literal.
(urlang
(urmodule js
(define (hello x) (+ "Hello " x))
(hello "world")))
"use strict";
function hello(x){return ("Hello "+x);};
(hello("world"));
(urlang
(urmodule js
(lambda ()
(define (hello x) (+ "Hello " x))
(hello "world"))))
; readline-input:29:7: parse-expr: expected an expression, got
; #<syntax:readline-input:29:7 define>
; in: define
; [,bt for context]
(urlang
(urmodule js
(var [y (lambda ()
(define (hello x) (+ "Hello " x))
(hello "world"))])))
; readline-input:42.4: var: expected Fixnum; expected Flonum; expected String;
; expected Boolean; expected Application; expected Sequence; expected
; Ternary; expected Assignment; expected Let; expected Lambda; expected
; ArrayReference; expected Array; expected New; expected Object; expected
; Dot; expected Id; or expected one of these identifiers: `while', `var',
; `block', `do-while', `sif', `break', `continue', `return', `label',
; `begin', `if', `:=', `let', `lambda', `λ', `ref', `array', `new', `object',
; or `dot'
; at: define
; in: (var (y (lambda () (define (hello x) (+ "Hello " x)) (hello "world"))))
; parsing context:
; while parsing different things...
; while parsing Body
; term: ((define (hello x) (+ "Hello " x)) (hello "worl...
; location: readline-input:42.12
; while parsing Lambda
; term: (lambda () (define (hello x) (+ "Hello " x)) (h...
; location: readline-input:42.12
; while parsing Expr
; term: (lambda () (define (hello x) (+ "Hello " x)) (h...
; location: readline-input:42.12
; while parsing VarBinding
; term: (y (lambda () (define (hello x) (+ "Hello " x))...
; location: readline-input:42.9
; [,bt for context]
I guess (define)
is missing from the allowed syntax in (lambda)
or in (var)
.
Running Urlang file with Node (current-urlang-run #t) or any node modules (babel, js-beautify) will result in an error:
"System can't find the path specified"
Implement "New Expressions":
JavaScript: new constructor [([arguments])]
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.