Dallycot

A linked open code engine

View project on GitHub

Core Library

The definitions provided by this library operate on functions to produce new functions.

Functions

length

Returns the length of the value. For stream-like values, this is how many values are in the stream. For strings, this is how many characters are in the string. For numeric values, this is how many base-10 digits are in the non-fractional part (i.e., the base-10 magnitude of the absolute value).

N.B.: This function will not expand streams. If the tail of the stream is a promise to generate more values, the length of the stream will be inf, using the sense of “unbounded” rather than the colloquial sense of “too large to count.”

Examples

length("The big bad bear") = 16
length(1..5) = 5
length(list-cons(1..3, 5..6)) = inf
length(12.345) = 2
length(-234) = 3

Implementation

This is implemented internally.

list-cons

Creates a new stream that acts as if the two given streams are concatenated.

Examples

list-cons(1..4, 6..10) = [ 1, 2, 3, 4, 6, 7, 8, 9, 10 ]

Implementation

list-cons := y-combinator(
  (self, first, second) :> (
    (?first) : [ first', self(self, first..., second) ]
    (      ) : second
  )
)

nest

Composes a function with itself a given number of times.

Examples

nest(f, 3) = f . f . f = { f(f(f(#))) }/1

Implementation

nest := y-combinator(
  (self, function, count) :> (
    (count > 3) : function . function . function . self(self, function, count-3)
    (count = 3) : function . function . function
    (count = 2) : function . function
    (count = 1) : function
    (         ) : { () }/1
  )
)