How to resolve the algorithm Function definition step by step in the EchoLisp programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Function definition step by step in the EchoLisp programming language

Table of Contents

Problem Statement

A function is a body of code that returns a value. The value returned may depend on arguments provided to the function.

Write a definition of a function called "multiply" that takes two arguments and returns their product. (Argument types should be chosen so as not to distract from showing how functions are created and values returned).

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Function definition step by step in the EchoLisp programming language

Source code in the echolisp programming language

(define (multiply a b) (* a b)) → multiply ;; (1)
(multiply 1/3 666) → 222

;; a function is a lambda definition :
multiply 
     → (λ (_a _b) (#* _a _b))

;; The following is the same as (1) :
(define multiply (lambda(a b) (* a b)))
multiply
    → (🔒 λ (_a _b) (#* _a _b)) ;; a closure


;; a function may be compiled
(lib 'compile)
(compile 'multiply "-float-verbose")

💡 [0]     compiling _🔶_multiply ((#* _a _b))
;; object code (javascript) :
var ref,top = _blocks[_topblock];
/* */return (
/* */(_stack[top] *_stack[1 + top]) 
/* */);

multiply  → (λ (_a _b) (#🔶_multiply)) ;; compiled function


  

You may also check:How to resolve the algorithm 15 puzzle solver step by step in the PowerBASIC programming language
You may also check:How to resolve the algorithm Sieve of Eratosthenes step by step in the J programming language
You may also check:How to resolve the algorithm A+B step by step in the Nutt programming language
You may also check:How to resolve the algorithm Cramer's rule step by step in the 11l programming language
You may also check:How to resolve the algorithm Integer sequence step by step in the Bracmat programming language