paulfitz / cosmicos

Sending the lambda calculus into deep space
https://cosmicos.github.io/
GNU General Public License v2.0
134 stars 8 forks source link

Message: removed "is" #36

Closed joha2 closed 2 years ago

joha2 commented 2 years ago

While looking at the first section and figuring out how to build an interpreter from scratch via Racket, I realized the is is somehow not useful and therefore I removed it. I had the following rationale:

Please tell me what you guys think.

Best wishes Johannes

alanfwilliams commented 2 years ago

This makes sense, and it really is just a small change. I'm happy to merge this once the travis ci is fixed.

paulfitz commented 2 years ago

The is change was deliberate, and simplified some work I was doing on a different representation of vocabulary. For implementation, you can think of it as a function that takes one parameter. Can you hold off on merging until I refresh my memory?

alanfwilliams commented 2 years ago

Sure.

paulfitz commented 2 years ago

Looking at 7983bda9, prior to becoming is foo these parts of the message were is:foo. If the is foo form feels worse, I'm ok reverting it, but would prefer is:foo rather than is-foo. There is some code to render the message using symbols from a rich alphabet, and x:y will be rendered in a way that composes the rendering of x and y, whereas x-y would be treated as something entirely novel and unrelated to x or y.

Thanks for poking at this @joha2

joha2 commented 2 years ago

@aw1231 and @paulfitz Thank you for your fast response! I am perfectly fine with is:int, is:square, is:prime (at the end, the listener just gets the bitcode). In fact I tried to implement it immediately, when I saw your comment. But somehow it throws an error message that is:int is unrecognized. Do you know where this comes from? I just substituted the - by :. I did a ./make.sh clean and ./make.sh standard.

I did the following changes:

diff --git a/msg/COS_Intro.js b/msg/COS_Intro.js
index b2f9ef3..ccdaaf2 100644
--- a/msg/COS_Intro.js
+++ b/msg/COS_Intro.js
@@ -5,25 +5,25 @@ var cos = require("./cosmic");
 cos.language(2);

 cos.add("intro unary");
-cos.add("intro is-int");
+cos.add("intro is:int");
 for (var i=0; i<16; i++) {
     var ones = "";
     for (var j=0; j<i; j++) {
        ones += " 1";
     }
-    cos.add("is-int | unary" + ones + " 0");
+    cos.add("is:int | unary" + ones + " 0");
 }

-cos.add("intro is-square");
+cos.add("intro is:square");
 for (var i=0; i<6; i++) {
     var ones = "";
     for (var j=0; j<i*i; j++) {
        ones += " 1";
     }
-    cos.add("is-square | unary" + ones + " 0");
+    cos.add("is:square | unary" + ones + " 0");
 }

-cos.add("intro is-prime");
+cos.add("intro is:prime");
 var primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31];
 for (var i=0; i<primes.length; i++) {
     var prime = primes[i];
@@ -31,5 +31,5 @@ for (var i=0; i<primes.length; i++) {
     for (var j=0; j<prime; j++) {
        ones += " 1";
     }
-    cos.add("is-prime | unary" + ones + " 0");
+    cos.add("is:prime | unary" + ones + " 0");
 }
diff --git a/msg/COS_Message.scm b/msg/COS_Message.scm
index 9f8994f..e7ed7dc 100644
--- a/msg/COS_Message.scm
+++ b/msg/COS_Message.scm
@@ -23,9 +23,9 @@

 # this line is referred to later - change/move carefully
 (equal (list-ref $primer 0) | vector intro unary);
-(equal (list-ref $primer 1) | vector intro is-int);
-(equal (list-ref $primer 2) | vector is-int | vector unary 0);
-(equal (list-ref $primer 3) | vector is-int | vector unary 1 0);
+(equal (list-ref $primer 1) | vector intro is:int);
+(equal (list-ref $primer 2) | vector is:int | vector unary 0);
+(equal (list-ref $primer 3) | vector is:int | vector unary 1 0);
 (assign idx (list:find $primer | vector intro primer) |
   equal (list-ref $primer | + $idx 1) |
     quote @@ | equal (list-ref $primer 0) | vector intro unary);

and got the following result from ./make.sh standard:

Working on message: standard
Re-run cmake no build system arguments
-- Configuring done
-- Generating done
-- Build files have been written to: /cosmicos/build/standard
[  2%] Built target jshelpers
[  2%] Built target cli
[  4%] Built target UnlessDriver
[  4%] Built target Fritzifier
[ 51%] Built target primer
[ 51%] Generating assem2.json, ../index.txt, ../index.json
* evaluate.js failed on 6: {"role":"code","lines":["is:int | unary 0;"],"original":["is:int | unary 0;"],"dt":false,"parse":["is:int",[-1,"unary","0"]],"code":"12121011113121100003302312111302032233","spider":"&#xf173;&#xf174;&#xf248;&#xf14b;&#xf24a;&#xf204;&#xf24b;"}
Error Error: Symbol 'is:int' unrecognized
    at Function.js__$Boot_HaxeError.wrap (/cosmicos/build/standard/src/CosmicEval.js:3993:10)
    at $hx_exports.cosmicos.Evaluate.evaluateInContext (/cosmicos/build/standard/src/CosmicEval.js:1866:32)
    at $hx_exports.cosmicos.Evaluate.evaluateExpression (/cosmicos/build/standard/src/CosmicEval.js:1882:16)
    at $hx_exports.cosmicos.EvaluateCodec.encode (/cosmicos/build/standard/src/CosmicEval.js:2253:31)
    at $hx_exports.cosmicos.ChainCodec.encode (/cosmicos/build/standard/src/CosmicEval.js:1426:32)
    at CosmicDrive.complete_stanza_core (/cosmicos/src/assemble/CosmicDrive.js:244:11)
    at CosmicDrive.complete_stanza (/cosmicos/src/assemble/CosmicDrive.js:152:26)
    at Object.<anonymous> (/cosmicos/src/assemble/evaluate.js:38:26)
    at Module._compile (internal/modules/cjs/loader.js:956:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10) {
  val: "Symbol 'is:int' unrecognized",
  message: "Symbol 'is:int' unrecognized"
}

/cosmicos/src/assemble/evaluate.js:46
  throw(e);
  ^
Error: Symbol 'is:int' unrecognized
    at Function.js__$Boot_HaxeError.wrap (/cosmicos/build/standard/src/CosmicEval.js:3993:10)
    at $hx_exports.cosmicos.Evaluate.evaluateInContext (/cosmicos/build/standard/src/CosmicEval.js:1866:32)
    at $hx_exports.cosmicos.Evaluate.evaluateExpression (/cosmicos/build/standard/src/CosmicEval.js:1882:16)
    at $hx_exports.cosmicos.EvaluateCodec.encode (/cosmicos/build/standard/src/CosmicEval.js:2253:31)
    at $hx_exports.cosmicos.ChainCodec.encode (/cosmicos/build/standard/src/CosmicEval.js:1426:32)
    at CosmicDrive.complete_stanza_core (/cosmicos/src/assemble/CosmicDrive.js:244:11)
    at CosmicDrive.complete_stanza (/cosmicos/src/assemble/CosmicDrive.js:152:26)
    at Object.<anonymous> (/cosmicos/src/assemble/evaluate.js:38:26)
    at Module._compile (internal/modules/cjs/loader.js:956:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10) {
  val: "Symbol 'is:int' unrecognized",
  message: "Symbol 'is:int' unrecognized"
}
[ 97%] Built target assem
[100%] Built target harness
Result in build/standard
paulfitz commented 2 years ago

@joha2 if you look in src/cosmicos/Evaluate.hx you'll see the following definitions:

evaluateLine("@ is-int | ? x 1");  // should make this more precise
evaluateLine("@ is-prime | ? x | if (< $x 2) 0 | not | has-divisor-within (- $x 1) $x");
evaluateLine("@ is-square | ? x | has-square-divisor-within $x $x");
evaluateLine("@ is | ? x | if (= $x int) $is-int | if (= $x square) $is-square | if (= $x prime) $is-prime $undefined");

These and other uses of is-foo will need updating in order for tests of the message to pass. I'm a bit embarrassed by the is-int definition :-) but it is just for testing purposes.

paulfitz commented 2 years ago

Thanks @joha2!