diff --git a/CHANGELOG.md b/CHANGELOG.md index a5af92b9e..970eba068 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ * fix shadowing `syntax-rules` identifiers with let [#291](https://github.com/jcubic/lips/issues/291) * fix nested syntax rules with symbols after nested ellipsis * fix Dark Mode colors and scrolling of the page when using Bookmarklet on English Wikipedia +* remove dependencies on `cond` from `-->` macro so you can use use `-->` inside `cond` ## 1.0.0-beta.18 ### Breaking diff --git a/dist/std.min.scm b/dist/std.min.scm index 22e4e4792..0120ebc0d 100644 --- a/dist/std.min.scm +++ b/dist/std.min.scm @@ -35,7 +35,7 @@ (define (native.number x) "(native.number obj)\u000A\u000AIf argument is a number it will convert it to a native number." (if (number? x) (value x) x)) (define (value obj) "(value obj)\u000A\u000AFunction that unwraps LNumbers and converts nil to undefined." (if (eq? obj ()) undefined (if (number? obj) ((. obj "valueOf")) obj))) (define-macro (define-formatter-rule . patterns) "(rule-pattern pattern)\u000A\u000AAnaphoric macro for defining patterns for the formatter. With Ahead, Pattern and * defined values." (let ((rules (gensym "rules"))) (quasiquote (let (((unquote rules) lips.Formatter.rules) (Ahead (lambda (pattern) (let ((Ahead (.. lips.Formatter.Ahead))) (new Ahead (if (string? pattern) (new RegExp pattern) pattern))))) (* (Symbol.for "*")) (Pattern (lambda (pattern flag) (new lips.Formatter.Pattern (list->array pattern) (if (null? flag) undefined flag))))) (unquote-splicing (map (lambda (pattern) (quasiquote (--> (unquote rules) (push (tree->array (tree-map native.number (unquote-splicing pattern))))))) patterns)))))) -(define-macro (cond . list) "(cond (predicate? . body)\u000A (predicate? . body))\u000A\u000A(cond (predicate? => procedure)\u000A (predicate? => procedure))\u000A\u000AMacro for condition checks. For usage instead of nested ifs.\u000AYou can use predicate and any number of expressions. Or symbol =>\u000AFollowed by procedure that will be invoked with result\u000Aof the predicate." (if (pair? list) (let* ((item (car list)) (value (gensym)) (first (car item)) (fn (and (not (null? (cdr item))) (eq? (cadr item) (quote =>)))) (expression (if fn (caddr item) (cdr item))) (rest (cdr list))) (quasiquote (let (((unquote value) (unquote first))) (if (unquote value) (unquote (if fn (quasiquote ((unquote expression) (unquote value))) (quasiquote (begin (unquote-splicing expression))))) (unquote (if (and (pair? rest) (or (eq? (caar rest) true) (eq? (caar rest) (quote else)))) (quasiquote (begin (unquote-splicing (cdar rest)))) (if (not (null? rest)) (quasiquote (cond (unquote-splicing rest)))))))))) ())) +(define-macro (cond . list) "(cond (predicate? . body)\u000A (predicate? . body))\u000A\u000A(cond (predicate? => procedure)\u000A (predicate? => procedure))\u000A\u000AMacro for condition checks. For usage instead of nested ifs.\u000AYou can use predicate and any number of expressions. Or symbol =>\u000AFollowed by procedure that will be invoked with result\u000Aof the predicate." (if (pair? list) (let* ((item (car list)) (value (gensym)) (first (car item)) (fn (and (not (null? (cdr item))) (eq? (cadr item) (quote =>)))) (expression (if fn (caddr item) (cdr item))) (rest (cdr list))) (quasiquote (let (((unquote value) (unquote first))) (if (unquote value) (unquote (if fn (quasiquote ((unquote expression) (unquote value))) (quasiquote (begin (unquote-splicing expression))))) (unquote (if (and (pair? rest) (let ((x (caar rest))) (or (eq? x true) (and (symbol? x) (or (eq? x (quote else)) (eq? (--> (new lips.LString (x.literal)) (cmp "else")) 0)))))) (quasiquote (begin (unquote-splicing (cdar rest)))) (if (not (null? rest)) (quasiquote (cond (unquote-splicing rest)))))))))) ())) (define (%r re . rest) "(%r re)\u000A\u000ACreates a new regular expression from string, to not break Emacs formatting." (if (null? rest) (new RegExp re) (new RegExp re (car rest)))) (define (interaction-environment) "(interaction-environment)\u000A\u000AReturns the interaction environment equal to lips.env. This can be overwritten\u000Awhen creating new interpreter with lips.Interpreter." **interaction-environment**) (define (current-output-port) "(current-output-port)\u000A\u000AReturns the default stdout port." (let-env (interaction-environment) (--> **internal-env** (get (quote stdout))))) diff --git a/dist/std.scm b/dist/std.scm index dacf6cc2a..6d6b00d48 100644 --- a/dist/std.scm +++ b/dist/std.scm @@ -576,8 +576,11 @@ `(begin ,@expression)) ,(if (and (pair? rest) - (or (eq? (caar rest) true) - (eq? (caar rest) 'else))) + (let ((x (caar rest))) + (or (eq? x true) + (and (symbol? x) + (or (eq? x 'else) + (eq? (--> (new lips.LString (x.literal)) (cmp "else")) 0)))))) `(begin ,@(cdar rest)) (if (not (null? rest)) diff --git a/dist/std.xcb b/dist/std.xcb index 867eeb3b5..a1d109f83 100644 Binary files a/dist/std.xcb and b/dist/std.xcb differ diff --git a/lib/bootstrap.scm b/lib/bootstrap.scm index 2c2f1af51..8c1cb45bc 100755 --- a/lib/bootstrap.scm +++ b/lib/bootstrap.scm @@ -576,8 +576,11 @@ `(begin ,@expression)) ,(if (and (pair? rest) - (or (eq? (caar rest) true) - (eq? (caar rest) 'else))) + (let ((x (caar rest))) + (or (eq? x true) + (and (symbol? x) + (or (eq? x 'else) + (eq? (--> (new lips.LString (x.literal)) (cmp "else")) 0)))))) `(begin ,@(cdar rest)) (if (not (null? rest))