kevinlawler / kona

Open-source implementation of the K programming language
ISC License
1.36k stars 138 forks source link

valence error for (,/:\:) . x #588

Closed tangentstorm closed 4 years ago

tangentstorm commented 4 years ago
  {x,/:\:y} . (2 3 ;5 7 11)    / this is correct:
((2 5
  2 7
  2 11)
 (3 5
  3 7
  3 11))
  (,/:\:) . (2 3 ;5 7 11)     / should be the same
valence error
(,/:\:) . (2 3 ;5 7 11)
        ^
>

in K3:

  (,/:\:) . (2 3 ; 5 7 11)
((2 5
  2 7
  2 11)
 (3 5
  3 7
  3 11))
tavmem commented 4 years ago

Here is a related problem, which may (or may not) be the cause of this issue

In k2.8

  f: +
  g: ,/:\:

In kona

  f: +
  g: ,/:\:
syntax error
> 
tavmem commented 4 years ago

Looks like the "related problem":

  f: +
  g: ,/:\:
syntax error
>

is actually not related at all. I will open a separate issue for this.

tavmem commented 4 years ago

The syntax error of issue 590 has been fixed. However, here is another (possibly related) problem: In k2.8

  ,/:
,/:

In kona

  ./:
.
tavmem commented 4 years ago

Upon further inspection, the problem noted above regarding "./:" does not appear to be related to the original "valence" problem. The "./:" problem appears to be a "display" error.

If you make the following 2 simple code changes:

$ git diff
diff --git a/src/kc.c b/src/kc.c
index 130298c..e6b6dc7 100644
--- a/src/kc.c
+++ b/src/kc.c
@@ -278,7 +278,7 @@ I line(FILE*f, S*a, I*n, PDA*p)     //just starting or just executed: *a=*n=*p=0
     if(o&&k)O("Elapsed: %.7f\n",d);
   #endif
  next:
-  if(o && fam && !feci)show(k);
+  if(o && fam && !feci){ O("\nresult: %p",&k);sd_(k,2);O("\n"); }
   cd(k);
  cleanup:
   if(fCheck && (strlen(s)==0 || s[strlen(s)-1]<0)) exit(0);
diff --git a/src/kc.h b/src/kc.h
index 46a0f44..ef22889 100644
--- a/src/kc.h
+++ b/src/kc.h
@@ -6,6 +6,7 @@ K _dot_t();
 K newE(S s,K k);
 K newEntry(S s);
 K Kd();
+extern K sd_(K x,I f);
 extern K KTREE;
 extern K KONA_WHO;
 extern K KONA_PORT;
$ 

then you get a full dump of the result:

$ rlwrap -n ./k
kona      \ for help. \\ to exit.

  ,/:

result: 0x7ffd939fdee8     0x7fdc6798b080 0x7fdc6798b098            1-7 7 1   ,
     a0:    0x7fdc6798b098     .k
     a1:    0x7fdc6798b0a0     (nil)
     a2:    0x7fdc6798b0a8     0x7fdc679b7740 0x7fdc679b7758            1-6 -4 3   0x34 
0xa 
(nil)  
     a3:    0x7fdc6798b0b0     0x7fdc679b76c0 0x7fdc679b76d8            1-6 5 0   
.()
     a4:    0x7fdc6798b0b8     0x7fdc679b7600 0x7fdc679b7618            1-6 5 0   
.()
     a5:    0x7fdc6798b0c0     
     a6:    0x7fdc6798b0c8     
     a7:    0x7fdc6798b0d0     

Although the first line shows a type-7 entity (function) displayed only as "," However, you will note that "a2" contains 3 elements: "0x34", "0xa" and "(nil)" In the dispatch table in src/k.c you can see that

In other words, the full content of the result is contained in the function. However, the display is partial, and only shows "," for some reason. I will create a separate issue for this.

PS: This "display" problem was created and closed as issue #592.

tavmem commented 4 years ago

Here is a borderline case (in kona) for the current issue. "Each" works:

  (,') . (1 2;3 4)
(1 3
 2 4)

"Each Right" fails:

  (,/:) . (1 2;3 4)
valence error
(,/:) . (1 2;3 4)
      ^
> 

and "Each Left" fails:

  (,\:) . (1 2;3 4)
valence error
(,\:) . (1 2;3 4)
      ^
>