Skip to content

Commit

Permalink
Patch Tuesday - K
Browse files Browse the repository at this point in the history
  • Loading branch information
Wodan58 committed Sep 24, 2024
1 parent 6749f5b commit 8ce778e
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 43 deletions.
14 changes: 7 additions & 7 deletions 42minjoy.in1
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ begin of include file *)
%SET X = 1
%IF = X 1 11111
%IF = X 2 22222
.
.

(* ALTERNATIVE RADIX for input numbers *)

(* default alternative radix is 2 *)
&1000000 .
&1000000 .
(* change default alternative radix *) %RADIX 8
&100 .
&100 .
(* change default alternative radix *) %RADIX 16
&FF .
&FF .

(* SCAN-TIME EXPRESSIONS IN CHARACTER CONSTANTS *)

%SET L = 65
'\L .
'\ + L 32 .
'\L .
'\ + L 32 .
%SET L = 'G
'\ + L - 'a 'A .
'\ + L - 'a 'A .

(* end of include file *)
6 changes: 3 additions & 3 deletions 42minjoy.in2
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
(* RECURSIVE FUNCTIONS, non-recursive computation *)

(* "last" is a tail-recursive function *)
[ Smith Jones Robinson ] last .
[ Smith Jones Robinson ] last .
(* now let us look at the (recursive) definition of "last" *)
[last] definition .
[ Smith Jones Robinson ] [last] definition i .
[last] definition .
[ Smith Jones Robinson ] [last] definition i .
(* using the x-combinator *)
[Smith Jones Robinson]
[ swap dup rest null
Expand Down
8 changes: 6 additions & 2 deletions 42minjoy.lib
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
(* vi: filetype=joy

module : 42minjoy.lib
version : 1.6
date : 04/19/24
version : 1.7
date : 09/24/24

Set F to 1 : include definition for fib
Set F to 0 : exclude definition for fib
Expand Down Expand Up @@ -91,8 +91,10 @@ the two operands might be a list. *
first == uncons pop ;
fix == [duco] first swap cons duco ;
fold == [swap] dip step ;
(*
foldl == [] rollup stepl ;
foldr == [] rollup stepr ;
*)
hidefirst == dip ;
hidesecond == [swap] dip dip swap ;
(*
Expand Down Expand Up @@ -203,7 +205,9 @@ X pop == *
square == dup * ;
succ == 1 + ;
sum == 0 [+] fold ;
(*
sumuntried == [] 0 [+] foldl ;
*)
(*
X Y swap == Y X *
*)
Expand Down
1 change: 1 addition & 0 deletions joy.vim
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ syntax match joySpecial /%INCLUDE/
syntax match joySpecial /%PUT/
syntax match joySpecial /%LISTING/
syntax match joySpecial /%TRACE/
syntax match joySpecial /%COMPILE/

if version >= 508 || !exists("did_joy_syntax_inits")
if version < 508
Expand Down
62 changes: 31 additions & 31 deletions tutorial.joy
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(*
module : tutorial.joy
version : 1.2
date : 04/19/24
version : 1.3
date : 09/24/24
*)
%LISTING 1
(*
Expand All @@ -14,46 +14,46 @@ of any type is a value of type list.
*)

(* push two numbers onto stack, add them, write result *)
111 222 + .
111 222 + .
(* add two numbers, add another two numbers, write product *)
1 2 + 3 4 + * .
1 2 + 3 4 + * .
(* testing whether 2 + 2 = 2 * 2 *)
2 2 + 2 2 * = .
2 2 + 2 2 * = .
(* testing whether 6 * 6 > 5 * 7 *)
6 6 * 5 7 * > .
6 6 * 5 7 * > .
(* Boolean operations *)
true false or true and not .
true false or true and not .

(* LISTS *)

(* push a list of numbers, reverse it, write result *)
[1 2 3 4 5] reverse .
[1 2 3 4 5] reverse .
(* push two lists of symbols, concatenate, write result *)
[peter paul] [mary jane] concat .
[peter paul] [mary jane] concat .
(* push a list of mixed values, write its last element *)
[11 false 'X 44] last .
[11 false 'X 44] last .
(* push a number and a list, determine membership *)
3 [1 5 3 4 2] member .
(* similar *)
3 [1 5 6 4 2] member .
(* push a list of numbers, duplicate to find sum and product *)
[1 2 3 4] dup sum put space put product .
(* push a number and a list of numbers, cons together *)
111 [ 222 333 ] cons .
111 [ 222 333 ] cons .
(* push a list, uncons twice, write remainder and first two *)
[11 22 33 44 55] uncons uncons putsp putsp .
(* push two lists of characters, concatenate them *)
[ 'a 'b ] [ 'd 'e 'f ] concat
(* now write result, but dup first so list is not lost *)
dup .
dup .
(* insert the missing 'c *)
uncons uncons 'c swap cons cons cons
(* now check *)
dup .
dup .
(* what is its length ? *)
dup length .
dup length .
(* reverse it, write its length *)
reverse length .
reverse length .
(* So, the length of a list is also the length of its reverse:
length == reverse length
*)
Expand All @@ -67,31 +67,31 @@ Combinators are operations which expect a list on top
of the stack and then execute it as a program.
*)
(* push two numbers and a program, i-combinator to execute *)
111 222 [+ put] i .
111 222 [+ put] i .
(* i-combinator to execute [+ put] on top of stack *)
111 [put +] reverse 222 swap i .
111 [put +] reverse 222 swap i .
(* dip-combinator to multiply 3 and 7, then add 100 *)
3 7 100 [*] dip + .
3 7 100 [*] dip + .
(* step-combinator to apply program to each member of list *)
[1 2 3] [dup * putsp] step .
[1 2 3] [dup * putsp] step .

(* i-combinator, twice-combinator, thrice-combinator *)
2 [dup *] i .
2 [dup *] twice .
2 [dup *] thrice .
2 [dup *] i .
2 [dup *] twice .
2 [dup *] thrice .
(* times-combinator, using definition square == dup * *)
2 0 [square] times .
2 1 [square] times .
2 2 [square] times .
2 3 [square] times .
2 4 [square] times .
2 5 [square] times . (* note overflow *)
10 [7] times stack .
2 0 [square] times .
2 1 [square] times .
2 2 [square] times .
2 3 [square] times .
2 4 [square] times .
2 5 [square] times . (* note overflow *)
10 [7] times stack .

(* map-combinator to make list of squares *)
[1 2 3] [dup *] map .
[1 2 3] [dup *] map .
(* fold-combinator to add squares of members of list *)
[1 2 3] 0 [dup * +] fold .
[1 2 3] 0 [dup * +] fold .
(* construct-combinator to make list from programs *)
11 12 (* push two numbers *)
[ (* make a list of .. *)
Expand Down

0 comments on commit 8ce778e

Please sign in to comment.