Code Monkey home page Code Monkey logo

urlang's Issues

Fails to build on the pkg-build server

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 think (ref ...) is still broken at the top level.

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"];

Detect duplicate names in object literals

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.

racket bindings interfering with urlang bindings of the same name

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?

Dot identifiers in assignment positions.

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)

Macro problem

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.

Modules

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.

binding error

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;})());

Fix mangling of last part of dotted identifiers

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.

Can I assign to a field nested N levels into an object?

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.

Can't `define` inside a `define`...

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

Failure while building urlang docs

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

Creating a string in Racket and using it in Urlang

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?

How to export default modules?

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.

multiple requires using the same MODULE var

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.

Support spread in object literals.

The spread operator ... can be used like this:

{...styles, color: "red"}

In Urlang, allow a spread operator at the beginning of an object literal.

(define) is not allowed inside a (lambda) form

This works:

(urlang
  (urmodule js
    (define (hello x) (+ "Hello " x))
    (hello "world")))
"use strict";
function hello(x){return ("Hello "+x);};
(hello("world"));

This does not and seems to trigger a Racket parsing error:

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

This does not either and is what I'd like to do:

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

Urlang won't work with NodeJS on Windows

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"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.