Files
2012-02-21 01:15:00 -05:00

1 line
4.3 KiB
JSON

[{"user_id": 32737, "stars": [], "topic_id": 41190, "date_created": 1309882112.112042, "message": "With my work on arc2js, I ran into a rather annoying limitation. Because it is a compiler and not an interpreter, it can only understand macros. That means that `(let a 5 a)` is translated correctly, because `let` is a macro. But `(isa x 'foo)` will translate to `isa(x, \"foo\")` which is not what you want.\n\nThe problem is fundamentally that functions are opaque blobs: you cannot inspect them in any way, aside from using `sig` to check their argument signature. If I had some way of inspecting their body, then I could treat functions like as if they were macros, and expand them at compile-time. This would allow things like `isa` to work.\n\nSo, what I would like is a \"fninfo\" function or similar. It would accept a single argument: a function. It would return a list of 3 elements. The first would be the function's name (`nil` if it's an anonymous function). The second would be the function's argument list. And the third would be the function's body.\n\nWith this change, not only would we be able to inspect any function's body, but we would also be able to inspect the argument list of anonymous functions (which is impossible with `sig`). And in fact, `sig` would then be redundant.\n\nBy the way, I'm not suggesting to make a function's body/argument list *mutable*. Right now I only care about getting *read-only* information. We can worry about mutability later.\n\nAlso, this isn't the sort of thing that can be done as a library... because it needs to work for functions defined in arc.arc, like `isa` for instance. So it will need to be defined either at the compiler level, or very early in arc.arc.\n\nUnless, of course, you can figure out a way to retroactively implement this as a library. That would be nice, but I don't think that's possible.", "group_id": 9739, "id": 1568394}, {"user_id": 25438, "stars": [], "topic_id": 41190, "date_created": 1310057344.7345531, "message": "This would be ugly, but as an easier way to get started at first, perhaps a library could implement a fninfo for new functions, and then read arc.arc to populate the function information data for the functions that have already been defined.", "group_id": 9739, "id": 1585569}, {"user_id": 25438, "stars": [], "topic_id": 41190, "date_created": 1310060278.2046759, "message": "Ah, but of course to implement it as a library (even if only for new functions loaded after the library), I need to pull in your redefining special forms like fn.", "group_id": 9739, "id": 1586015}, {"user_id": 25438, "stars": [], "topic_id": 41190, "date_created": 1310142052.942538, "message": "@Pauan I checked in a stab at an \"fninfo\" implementation; not very good but I hope enough to let you move forward with arc2js. It loads after arc, so it reads arc.arc itself and fills in the info from the \"def\" forms. Naturally this doesn't capture the anonymous functions defined before fninfo gets loaded; please let me know if you'll need those for arc2js or if anything else is missing. (Anonymous functions defined after fninfo is loaded do have their function information recorded). It uses the label style of associating information with functions, so you can say \"(fn-args isa)\" to get \"(x y)\" and \"(fn-body isa)\" to get \"((is (type x) y))\".", "group_id": 9739, "id": 1594146}, {"user_id": 32737, "stars": [], "topic_id": 41190, "date_created": 1310199924.0555229, "message": "hm... wait, sig isn't needed because of fn-args... that should make this a bit easier, then. Here's one implementation of fn-info:\n\n(def fn-info (x)\n (cons (name x)\n (cons (fn-args x)\n (fn-body x))))\n\nThe name won't be meaningful (it'll just be a gensym) until functions are given proper names.", "group_id": 9739, "id": 1598049}, {"user_id": 32737, "stars": [], "topic_id": 41190, "date_created": 1310199375.952096, "message": "For what it's worth, I think it's better to have a single function that returns a list, because then you can do this:\n\n(let (name args body) (fninfo foo)\n ...)\n\nRather than this:\n\n(with (name (sig 'foo)\n args (fn-args foo)\n body (fn-body foo))\n ...)\n\nHowever, it's possible to define \"fninfo\" in terms of sig, fn-args, and fn-body, so I'll give that a try, thanks.", "group_id": 9739, "id": 1598040}]