70b847a649b8 — Leonard Ritter 14 days ago
* added `<-:` operator for nicer function construction
2 files changed, 21 insertions(+), 13 deletions(-)

M lib/scopes/core.sc
M src/type/function_type.cpp
M lib/scopes/core.sc +13 -1
@@ 3512,6 3512,17 @@ let
                 raising Error
                 let f args = (decons expr 2)
                 qq ([f] [args])
+    <-: =
+        sugar-macro
+            fn expand-apply (expr)
+                raising Error
+                let ret args = (decons expr 2)
+                if (== ('typeof args) Nothing)
+                    let ret = (as ret list)
+                    qq ([function] [void] (unquote-splice ret))
+                else
+                    let args = (as args list)
+                    qq ([function] [ret] (unquote-splice args))
 
 #define-infix< 40 , _
 

          
@@ 3553,11 3564,12 @@ define-infix> 600 //
 define-infix> 600 *
 define-infix< 700 ** pow
 define-infix> 750 as
-define-infix> 750 raises
 define-infix> 780 :
 define-infix> 800 .
 define-infix> 800 @
 define-infix> 800 <-
+define-infix> 800 <-:
+define-infix> 800 raises
 
 # (va-option key args... else-body)
 let va-option =

          
M src/type/function_type.cpp +8 -12
@@ 25,27 25,23 @@ namespace scopes {
 //------------------------------------------------------------------------------
 
 void FunctionType::stream_name(StyledStream &ss) const {
-    bool exc = has_exception();
-    if (exc) {
-        ss << "(";
-    }
     ss << "(";
-    if (vararg()) {
-        ss << "variadic function ";
-    } else {
-        ss << "function ";
-    }
     stream_type_name(ss, return_type);
+    ss << " <-: (";
     for (size_t i = 0; i < argument_types.size(); ++i) {
-        ss << " ";
+        if (i > 0)
+            ss << " ";
         stream_type_name(ss, argument_types[i]);
     }
+    if (vararg()) {
+        ss << " ...";
+    }
     ss << ")";
-    if (exc) {
+    if (has_exception()) {
         ss << " raises ";
         stream_type_name(ss, except_type);
-        ss << ")";
     }
+    ss << ")";
 }
 
 FunctionType::FunctionType(const Type *_except_type,