Permalink
Browse files

equality on values other than strings, by using underlying equality o…

…f host
  • Loading branch information...
namin committed Nov 7, 2017
1 parent 9bf0737 commit c0ee7aac0b357c640a76dd363c5a4a2a8e36e2c9
Showing with 9 additions and 9 deletions.
  1. +8 −8 popl18/base.scala
  2. +1 −1 popl18/lisp.scala
@@ -15,7 +15,7 @@ object Base {
case class Plus(a:Exp,b:Exp) extends Exp
case class Minus(a:Exp,b:Exp) extends Exp
case class Times(a:Exp,b:Exp) extends Exp
case class Equs(a:Exp,b:Exp) extends Exp
case class Equ(a:Exp,b:Exp) extends Exp
case class Cons(a:Exp,b:Exp) extends Exp
case class Fst(a:Exp) extends Exp
case class Snd(a:Exp) extends Exp
@@ -85,8 +85,8 @@ object Base {
reflect(Times(anf(env,e1),anf(env,e2)))
case Minus(e1,e2) =>
reflect(Minus(anf(env,e1),anf(env,e2)))
case Equs(e1,e2) =>
reflect(Equs(anf(env,e1),anf(env,e2)))
case Equ(e1,e2) =>
reflect(Equ(anf(env,e1),anf(env,e2)))
case Cons(e1,e2) =>
reflect(Cons(anf(env,e1),anf(env,e2)))
case IsNum(e) =>
@@ -228,12 +228,12 @@ object Base {
case (Code(s1),Code(s2)) =>
reflectc(Times(s1,s2))
}
case Equs(e1,e2) =>
case Equ(e1,e2) =>
(evalms(env,e1), evalms(env,e2)) match {
case (Str(s1), Str(s2)) =>
Cst(if (s1 == s2) 1 else 0)
case (v1, v2) if !v1.isInstanceOf[Code] && !v2.isInstanceOf[Code] =>

This comment has been minimized.

@TiarkRompf

TiarkRompf Nov 7, 2017

Owner

(Wrote a comment, but never mind, this is OK)

This comment has been minimized.

@namin

namin Nov 7, 2017

Collaborator

The case you're worried about is currently an error.

This comment has been minimized.

@TiarkRompf

TiarkRompf Nov 7, 2017

Owner

duh, yes, I misread. sorry ...

This comment has been minimized.

@namin

namin Nov 7, 2017

Collaborator

In any case, feel free to change to strongly typed if you feel .. strongly. The tests should still pass and one variant vs the other does not affect anything in the paper.

This comment has been minimized.

@TiarkRompf

TiarkRompf Nov 7, 2017

Owner

No, I think it's ok. We just shouldn't be able to mix code and other values, but I don't see much harm in comparing Int and String

Cst(if (v1 == v2) 1 else 0)
case (Code(s1),Code(s2)) =>
reflectc(Equs(s1,s2))
reflectc(Equ(s1,s2))
}
case Cons(e1,e2) =>
// introduction form, needs explicit lifting
@@ -297,7 +297,7 @@ object Base {
case Lift(a) => s"(lift ${pretty(a,env)})"
case Fst(a) => s"(car ${pretty(a,env)})"
case Snd(a) => s"(cdr ${pretty(a,env)})"
case Equs(a,b) => s"(eq? ${pretty(a,env)} ${pretty(b,env)})"
case Equ(a,b) => s"(eq? ${pretty(a,env)} ${pretty(b,env)})"
case Plus(a,b) => s"(+ ${pretty(a,env)} ${pretty(b,env)})"
case Minus(a,b) => s"(- ${pretty(a,env)} ${pretty(b,env)})"
case Times(a,b) => s"(* ${pretty(a,env)} ${pretty(b,env)})"
@@ -57,7 +57,7 @@ object Lisp {
case Tup(Str("cadddr"), Tup(a,N)) => Fst(Snd(Snd(Snd(trans(a,env)))))
case Tup(Str("lift"), Tup(a,N)) => Lift(trans(a,env))
case Tup(Str("nolift"), Tup(a,N)) => trans(a,env)
case Tup(Str("eq?"), Tup(a,Tup(b,N))) => Equs(trans(a,env),trans(b,env))
case Tup(Str("eq?"), Tup(a,Tup(b,N))) => Equ(trans(a,env),trans(b,env))
case Tup(Str("run"), Tup(b,Tup(a,N))) => Run(trans(b,env),trans(a,env))
case Tup(Str("log"), Tup(b,Tup(a,N))) => Log(trans(b,env),trans(a,env))
case Tup(Str("quote"), Tup(a,N)) => Special(benv => a)

0 comments on commit c0ee7aa

Please sign in to comment.