ohua-dev / ohua-jvm-integration

Integration for the ohua core library with the java platform
Eclipse Public License 1.0
2 stars 0 forks source link

[Feature] Algos with no arguments #7

Open JustusAdam opened 6 years ago

JustusAdam commented 6 years ago

In clojure it makes sense to define functions with no arguments to delay an evaluation or to perform side-effects.

(defn f []
  some-effect)

(let [x (f)]
  ...)

As this makes sense for ohua too we should support algorithms without arguments too.

Example

(defalgo f []
  some-effect)

(ohua 
  (smap
    (algo [a] .. (f) ...) ; f is executed multiple times
    [...]))

ALang however makes no distinction between a value invoking a function. A possible way to solve this is by adding a dummy ignored _ argument and inserting a unit argument at the call site.

The most important thing to do is to figure out how to ensure the inlined let _ = unit in ... bindings after applying a function like (λ _ . ...) unit are removed at the appropriate time.

Perhaps to this end it may be beneficial to distinguish the ignored binding _ explicitly rather than just making it the binding "_".

Something like

data Bnd 
    = Real Binding
    | Ignored -- `_` 
sertel commented 6 years ago

I may have a simpler suggestion: Our ALang is purely functional and therefore can not understand what (f) means. I believe that the adaptation of our Clojure frontend to ALang should handle this case. As such, there should be a rewrite like this (f) -> (f (unit)) where unit is a built-in stateful function. No changes to ALang would then be necessary. As far as performance goes, this is again something that we can optimize via fusion or another optimization maybe in DFLang. I would vote for not changing our ALang towards that.