Closed asukaminato0721 closed 3 months ago
Hah, amazing! I didn't know about this :D As always, everything was done before, we just forgot or did not know
I think I came across with that on some stackexchange topics, where the guy asked how to call a function by a string typed by a user.
Btw, I think in such case scenario it is good to keep it simple in this way, that on some pages/or projects the functions can be extended by simple
core.Something = function(arg, env) {
}
therefore, it can fully integrate Wolfram Language with a static or dynamic web page via websockets, so one can say symbolic computations meet web-design (I did it in one of the side projects, which is basically a multipurpose web application working in the exact same fashion).
Mb the fact that somewhere var core
is defined and cannot be redefined by a user makes me feel, there must a better solution like
new evaluator core(new web socket(), or some handler);
core.function1Name = function(arg, env) {
}
//or if it is a module
import {graphics3d} from @graphics3d;
import {graphics2d} from @graphics2d;
graphics3d.extend(core);
graphics2d.extend(core);
but since I am dumb in modern JS, I am afraid to step in to this territory ;)
actually, by using ESM, this is very easy.
a.js
export const f = (a) => a+1;
export function g(b) {
console.log(b);
}
just export them, needless to interact with core.
b.js
import * as a from "./a.js"
console.log(a['f'](1), a.f(1));
a['g'](2);
a.g(2);
put them in the same folder, and run node b.js
, it just works. :)
by the way, try vite , it's very nice. (and support ESM out of the box). node currently need use .mjs
or set "type" : "module"
in package.json
if a.ts and b.ts or with .d.ts, we can even have the type hint :P.
but it's not good for this project. since a need function in b, b need functions in a.
so just core.NewFunction
is ok :P
but it's not good for this project. since a need function in b, b need functions in a.
so just
core.NewFunction
is ok :P
Well, such a pity actually. I hope it will not introduce any troubles in future.
regarding vite, it would be so so cool, if it could pull necessary modules when, for example core.Graphics3D was called, and then, the module was about to downloaded.
Offtopic. Came across Observable, jeez it looks so great. UI and data visualization are great, but you can't edit the output cells... eh
this parser is much like https://sourceacademy.org/sicpjs/4.1.1 .
(I am a fan of this topic (functional programming), by the way. I have completed the sicp-py, cs61a)
so it's needless to write a huge switch case, and
core.NewMethod
just works.sicp is one of my favourite book :)