Cléber Zavadniak
2022
https://cleber.solutions/
"How do I create a JS function
to be called recursively
that retains state
but without access to global/outer scope?"
% 1- The "interface" function:
fib(N) -> fib_iter(N, 0, 1).
% 2- The break:
fib_iter(0, Result, _Next) -> Result;
% 3- The iteration:
fib_iter(Iter, Result, Next) ->
fib_iter(Iter-1, Next, Result+Next).
fib(N) -> fib_iter(N, 0, 1).
fib_iter(0, Result, _Next) -> Result;
fib_iter(Iter, Result, Next) ->
fib_iter(Iter-1, Next, Result+Next).
fib(3) % interface
fib_iter(3, 0, 1) % iteration
fib_iter(2, 1, 1) % iteration
fib_iter(1, 1, 2) % iteration
fib_iter(0, 2, 3) % break
2 % result
Index: 0 1 2 3
Sequence: 0 1 1 2
Before we really start,
of (probably) very useful "useless" things.
It's Redis! See https://gist.github.com/antirez/6ca04dd191bdb82aad9fb241013e88a8
Forget it.
swipl -f awesome.pl
swipl -f roads.pl
path(a, e, Path, Distance).
path(a, e, Path, Distance), [H|T] = Path, [H2|T2] = T, H2 = b.
append([a], [b], X).
append(A, B, [a, b, c, d]).
<comma> = AND | <semicolon> = OR/ELSE | <period> = END
See:
https://medium.com/clebertech-en/prolog-is-not-that-hard-f8cb2b8b3e43
https://medium.com/clebertech-en/prolog-is-not-that-hard-part-2-3a88ac8f02e0
Interesting example: "julian"
Date and time, based only on constraints.
:- use_module(library(julian)). :- use_module(library(clpfd)). solution(Year) :- % Eisenhower presidency had % Fourth of July on Sunday in ... form_time([dow(sunday), Year-07-04]), Year in 1953..1961. ?- solution(Y). Y = 1954.
See also:
"concatenative" is not a synonym
with "stack based".
Concatenative:
Prog_A <concat operation> ProgB =
Prog_B(Prog_A)
\ Display indexes of a 2D array : INDEXES ( rows columns -- ) SWAP ( columns rows ) 0 ?DO \ For number of rows CR \ CR goes to next line DUP \ DUPlicate columns 0 ?DO \ For number of rows J . \ Display row index I . \ Display column index SPACE \ SPACE displays a space LOOP \ End of inner loop LOOP ; \ End of outer loop 3 4 INDEXES
Imagine you have only
32 bytes
of available memory
and have to run some fairly complex algorithms.
Argo Submersible Vehicle
(Now retired) Space Shuttle
My advice:
Take some time to study some absurd topic.