From 929ae557ed092e53aaf46588fd34e86abe402d44 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Fri, 8 Aug 2025 12:10:11 -0500 Subject: [PATCH] allow :Null on lambda and arrow lambda --- src/kiss/Reader.hx | 11 +++++++++-- src/kiss/SpecialForms.hx | 5 ++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/kiss/Reader.hx b/src/kiss/Reader.hx index 33496a1..a531938 100644 --- a/src/kiss/Reader.hx +++ b/src/kiss/Reader.hx @@ -178,7 +178,7 @@ class Reader { // -+>countVar arg body // -+>countVar {body} // -+>countVar (body) - // or any of those with the first expression after -> or -+> prefixed by :Void + // or any of those with the first expression after -> or -+> prefixed by :Void or :Null function arrowSyntax(countingLambda:Bool, stream:Stream, k:HasReadTables) { var countVar = if (countingLambda) { _assertRead(stream, k); @@ -192,10 +192,14 @@ class Reader { var bodyExp:ReaderExp = null; var returnsValue = true; + var returnsNull = false; switch (firstExp.def) { case TypedExp("Void", realFirstExp): firstExp = realFirstExp; returnsValue = false; + case TypedExp("Null", realFirstExp): + firstExp = realFirstExp; + returnsNull = true; default: } switch (firstExp.def) { @@ -209,10 +213,13 @@ class Reader { argsExp = b.list([]); bodyExp = firstExp; default: - throw KissError.fromExp(firstExp, "first expression after -> should be [args...], arg, (exp) or {body}, or one of those prefixed with :Void. When an argument type must be specified, even a single argument name must be put in brackets. For example: ->[:ArgType arg] "); + throw KissError.fromExp(firstExp, "first expression after -> should be [args...], arg, (exp) or {body}, or one of those prefixed with :Void or :Null. When an argument type must be specified, even a single argument name must be put in brackets. For example: ->[:ArgType arg] "); } if (!returnsValue) { argsExp = TypedExp("Void", argsExp).withPosOf(argsExp); + } else if(returnsNull) { + argsExp = TypedExp("Null", argsExp).withPosOf(argsExp); + bodyExp = b.begin([bodyExp, b.callSymbol("return", [b.symbol("null")])]); } return if (countingLambda) { CallExp(b.symbol("countingLambda"), [countVar, argsExp, bodyExp]); diff --git a/src/kiss/SpecialForms.hx b/src/kiss/SpecialForms.hx index 835d50d..4e731b2 100644 --- a/src/kiss/SpecialForms.hx +++ b/src/kiss/SpecialForms.hx @@ -271,12 +271,15 @@ class SpecialForms { block; }; - k.doc("lambda", 2, null, "(lambda [] )"); + k.doc("lambda", 2, null, "(lambda [] )"); map["lambda"] = (wholeExp:ReaderExp, args:Array, k:KissState) -> { var returnsValue = switch (args[0].def) { case TypedExp("Void", argNames): args[0] = argNames; false; + case TypedExp("Null", argNames): + args[0] = argNames; + true; default: true; }