JOY - compiled at 14:53:58 on Mar 14 2003 (NOBDW) Copyright 2001 by Manfred von Thun usrlib is loaded inilib is loaded numlib is loaded agglib is loaded seqlib is loaded agglib is loaded # from Little Lisper DEFINE str-maker == # n [N] => [n [N(n) [N] str-maker]] dupd dup [i] dip [str-maker] cons cons [] cons cons; str-first == first; str-rest == second i. DEFINE str-ints == 0 [succ] str-maker; str-pows == 1 [2 *] str-maker; str-prim == 2 [succ [prime not] [succ] while] str-maker; str-brak == [] [[] cons] str-maker. str-ints. [0 [1 [succ] str-maker]] str-pows. [1 [2 [2 *] str-maker]] DEFINE str-uncons == [str-first] [str-rest] cleave; str-third == str-rest str-rest str-rest str-first; str-tenth == 10 [str-rest] times str-first; str-drop == [str-rest] times; str-n-th == str-drop str-first; str-take == # S n => [S1 S2 .. Sn] [null] [pop pop []] [[str-uncons] dip pred] [cons] linrec. str-brak. [[] [[[]] [[] cons] str-maker]] str-brak str-third. [[[[]]]] str-pows. [1 [2 [2 *] str-maker]] str-pows str-tenth. 1024 str-ints 5 str-take. [0 1 2 3 4] str-pows 10 str-take. [1 2 4 8 16 32 64 128 256 512] str-prim 10 str-drop 10 str-take. [31 37 41 43 47 53 59 61 67 71] # using replicating DEFINE dureco == dup rest cons; rep-maker == # n [N] => [ [n [N] infra dureco] [N] infra dureco ] [infra dureco] cons cons dureco; rep-first == first first; rep-rest == i. DEFINE rep-ints == 0 [succ] rep-maker; rep-evns == 0 [2 +] rep-maker; rep-pows == 1 [2 *] rep-maker; rep-prim == 2 [succ [prime not] [succ] while] rep-maker; rep-brak == [] [[] cons] rep-maker. rep-ints. [[0 [succ] infra dureco] [succ] infra dureco] rep-pows. [[1 [2 *] infra dureco] [2 *] infra dureco] DEFINE rep-uncons == [rep-first] [rep-rest] cleave; rep-third == rep-rest rep-rest rep-rest rep-first; rep-tenth == 10 [rep-rest] times rep-first; rep-drop == [rep-rest] times; rep-n-th == rep-drop rep-first; rep-take == # S n => [S1 S2 .. Sn] [null] [pop pop []] [[rep-uncons] dip pred] [cons] linrec. rep-evns. [[0 [2 +] infra dureco] [2 +] infra dureco] rep-evns rep-rest rep-rest rep-first. 4 rep-brak. [[[] [[] cons] infra dureco] [[] cons] infra dureco] rep-brak rep-third. [[[[]]]] rep-pows. [[1 [2 *] infra dureco] [2 *] infra dureco] rep-pows rep-tenth. 1024 rep-ints 5 rep-take. [0 1 2 3 4] rep-pows 10 rep-take. [1 2 4 8 16 32 64 128 256 512] rep-prim 10 rep-drop 10 rep-take. [31 37 41 43 47 53 59 61 67 71] ÿ (* END usrlib.joy *)