Skip to content

Comment on Libfive: Solid modeling (CAD) library/tools with Scheme/Python bindings and GUIparent

Comments

I found it's really cool how you can prefix any variable with # and makes it interactivee. How do you map variables to draggable surface in studio?

Guile supports custom readers through read-hash-extend [1]: this lets you associate specific syntax with a custom reader, triggered by a '#' character. For example, this is how comments are implemented with #! ...multiline comment... !#: the first "#!" triggers a custom reader which reads until the termination.

libfive installs custom readers for #0, #1, #2, and so on, which all do the same thing: store the syntax position (row/column/span), then create a free variable with a particular id that's associated with that syntax position.

When pushing and pulling on the surface, it's solving for free variables values that put the surface at your mouse cursor's position. Then, it can splice those values back into the original script using the row/column/span data from before.

Python does the same thing with a magic `var(...)` function, which is used as the target for an AST transform here:

https://github.com/libfive/libfive/blob/master/libfive/bind/...

[1] http://www.gnu.org/software/guile/manual/guile.html#Reader-E...

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.