sharp integers (ex. #1 #2) and sharp primitives (#> #< #)
icpdesign — 2005-09-22 13:22:18
I am plyaing with the idea of extending Joy by a new data type
(sharp integer or #int) and 3 new sharp primitives (#> #< #).
#int (sharp integer):
ex. #1 #2 ...
#int are tagged integers; any expression using a sharp integer
results in a sharp integer
ex.
4 #1 + ==> #5
#1 #5 + 2 / #2 * ==> #6
converting sharp integers to integers:
#3 # ==> 3 // # converts a sharp integer to an integer
The following two primitives #> and <# replaces a sharp integer
#n by the element of the stack at position n, and leaves any non
sharp ineteger as it is:
#> pops the element from the stack, and
<# does not pop the element,
ex.
10 20 30 3 #> ==> 10 20 30 3
10 20 30 [5] <# ==> 10 20 30 [5]
10 20 30 #2 #> ==> 10 30 20
10 20 30 #2 <# ==> 10 20 30 20
10 20 30 [40 #2 +] <# i ==> 10 20 30 [40 20 +] i
==> 10 20 30 60
10 20 30 [40 #2 +] #> i ==> 10 30 [40 20 +] i
==> 10 30 60
10 20 30 [40 #2 + [#1 #2]] #> i ==> 10 30 [40 20 + [#1 #2]] i
==> 10 30 60 [#1 #2]
note that the #> did not replace the #int in the nested quotation;
I am not sure how #> and <# should deal with nested quotations, but
for now I think that the sharp primitives should be implemented
as following:
[Q] #> == replace all sharp integeres in the quotation [Q],
and pop their corresponding statck element
[Q] <# == replace all sharp integeres in the quotation [Q]
So, since [#1 #2] is not a sharp integer so it is not replaced
More to come, I hope I will be able in near future to define
formally this extensions; sharp integers, sharp primitives
Taoufik Dachraoui
icpdesign — 2005-09-22 13:58:14
I am just wondering if the conversion from #int to int is necessary.
Any thoughts? Also may be we need a conversion from int to #int
What if we use the same the conversion primitive to both conversions
like this:
3 # ==> #3
#3 # ==> 3
so # # ==> id
Taoufik Dachraoui
--- In
concatenative@yahoogroups.com, "icpdesign"
<taoufik.dachraoui@w...> wrote:
> I am plyaing with the idea of extending Joy by a new data type
> (sharp integer or #int) and 3 new sharp primitives (#> #< #).
>
> #int (sharp integer):
> ex. #1 #2 ...
>
> #int are tagged integers; any expression using a sharp integer
> results in a sharp integer
>
> ex.
> 4 #1 + ==> #5
> #1 #5 + 2 / #2 * ==> #6
>
> converting sharp integers to integers:
>
> #3 # ==> 3 // # converts a sharp integer to an integer
>
> The following two primitives #> and <# replaces a sharp integer
> #n by the element of the stack at position n, and leaves any non
> sharp ineteger as it is:
> #> pops the element from the stack, and
> <# does not pop the element,
>
> ex.
> 10 20 30 3 #> ==> 10 20 30 3
> 10 20 30 [5] <# ==> 10 20 30 [5]
> 10 20 30 #2 #> ==> 10 30 20
> 10 20 30 #2 <# ==> 10 20 30 20
>
> 10 20 30 [40 #2 +] <# i ==> 10 20 30 [40 20 +] i
> ==> 10 20 30 60
>
> 10 20 30 [40 #2 +] #> i ==> 10 30 [40 20 +] i
> ==> 10 30 60
>
> 10 20 30 [40 #2 + [#1 #2]] #> i ==> 10 30 [40 20 + [#1 #2]] i
> ==> 10 30 60 [#1 #2]
>
> note that the #> did not replace the #int in the nested quotation;
> I am not sure how #> and <# should deal with nested quotations, but
> for now I think that the sharp primitives should be implemented
> as following:
>
> [Q] #> == replace all sharp integeres in the quotation [Q],
> and pop their corresponding statck element
> [Q] <# == replace all sharp integeres in the quotation [Q]
>
> So, since [#1 #2] is not a sharp integer so it is not replaced
>
> More to come, I hope I will be able in near future to define
> formally this extensions; sharp integers, sharp primitives
>
> Taoufik Dachraoui
icpdesign — 2005-09-23 06:37:49
Originally I defined #> and <# as primitives that accepts sharp integers
or quotations or lists, but after thinking about this I find that it is better
to redefine #> and <# as follows:
#n #> ==> pops the nth element from stack and pushed on top
#n <# ==> reads the nth element from stack and pushed on top
X #> ==> X if X is not a sharp integer
As you see this match simpler, and using map we can have what I meant in my previous
message:
10 20 [1 [#1 #2] #1 #2] [#>] map ==> [1 [#1 #2] 20 10]
Taoufik Dachraoui