Convex-Dev / convex.cljc

Any aspect of the Convex stack, from Clojure
Apache License 2.0
53 stars 7 forks source link

Consider metadata in `$.cell/*` macro #5

Open helins opened 2 years ago

helins commented 2 years ago

For instance:

($.cell/*
 (defn ^{:callable? true} set-value-in-actor
   [x]
   (def value
     x)))

However metadata in CVX behave differently so this deserves some thoughts.

mikera commented 2 years ago

Best if we be consistent with the Reader convention, so that a metadata annotation causes the following form to be wrapped as a Syntax. See: https://github.com/Convex-Dev/convex/blob/22bb34e2a2c680f9eafe674b0f688c41413f746f/convex-core/src/main/java/convex/core/lang/reader/AntlrReader.java#L310

helins commented 2 years ago

Yes, essentially, however it's only going on IMeta

helins commented 1 year ago

(Follow-up on a Discord question about how to circumvent this for the time being).

The Reader converts ^{:metadata ...} value into to a Syntax (a type that wraps a value alongside a metadata map).

For the time being, using the $.cell/* macro, we can actually do it ourselves using convex.cell/syntax. We can use unquote for feeding any value that is already a cell.

Something like:

($.cell/*
 (defn ~($.cell/syntax ($.cell/* set-value-in-actor)
                       ($.cell/* {:callable? true}))
   [x]
   (def value
     x)))

Not as pretty as a literal notation but it works.

When working with a chunk of Convex Lisp code that does not need to be generated from Clojure, I recommend writing it to a dedicated file and use the reader. Setting your editor to Clojure syntax when writing Convex Lisp files works good enough on average.