• Or-Func, What is (make-list 3) good for? (besides Lazy-factorial) ???

    From HenHanna@21:1/5 to All on Tue Jun 18 13:35:30 2024
    1. Is there a better way to define Or-Func ?

    2. (make-list x) works well here. What else is it good for?

    3. What is (make-list 3) in MIT Scheme?
    Should (length (make-list 3)) raise an Error?



    (define (or-func2 x y) (or x y))
    (define or-func (lambda x (fold or-func2 #t x)))

    (define (fact x)
    (fold * 1
    (map or-func (make-list x) (lrange 1))))

    (print (fact 0))
    (print (fact 1))
    (print (fact 3))
    (print (fact 5))
    (print (fact 10))

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to HenHanna on Wed Jun 19 01:03:46 2024
    On 2024-06-18, HenHanna <HenHanna@devnull.tb> wrote:

    1. Is there a better way to define Or-Func ?

    2. (make-list x) works well here. What else is it good for?

    3. What is (make-list 3) in MIT Scheme?
    Should (length (make-list 3)) raise an Error?



    (define (or-func2 x y) (or x y))
    (define or-func (lambda x (fold or-func2 #t x)))

    (define (fact x)
    (fold * 1
    (map or-func (make-list x) (lrange 1))))

    (print (fact 0))
    (print (fact 1))
    (print (fact 3))
    (print (fact 5))
    (print (fact 10))

    This is the TXR Lisp interactive listener of TXR 294.
    Quit with :quit or Ctrl-D on an empty line. Ctrl-X ? for cheatsheet.
    If you get your macros hot enough, you get syntactic caramel!
    (fboundp 'or)
    t
    (mboundp 'or)
    nil
    (special-operator-p 'or)
    t
    (mapcar 'or '(1 nil nil 4) '(10 20 30 40))
    (1 20 30 4)

    No "or-func" required; or as a function can be provided in the language.

    We can have a Lisp dialect that allows us to bind the same symbol in both the macro/operator space and the function space.

    This causes no issues.

    When (or ...) syntax is processed, the operator or macro is activated.
    All other other function-like uses of the symbol go through the function binding.

    This design obviates the need for compiler macros (define-compiler-macro). For any given function, we can write an ordinary macro. That macro is always used, when the function is syntactically invoked.

    We must imbue ordinary macros with the ability to decline exmpansion by returning the original form; the expander must stop expanding when it
    hits a fixed point, according ot the EQ function (expander in is EQ
    to expander out).

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)