#The implementation of eval-fun is an exercise left to the reader
(def (eval-lambda-calculus eval-fun expr)
(eval-fun expr))
Name:
Anonymous2014-02-11 17:33
data Binding = NameBind
type Context = [(String, Binding)]
data Term = TmVariable Int Int
| TmAbstraction String Term
| TmApplication Term Term
deriving (Show, Eq)
termShift :: Int -> Term -> Term
termShift d t = walk 0 t
where walk c t = case t of
(TmVariable x n) -> if x >= c then (TmVariable (x+d) (n+d))
else (TmVariable x (n+d))
(TmAbstraction x t) -> (TmAbstraction x (walk (c+1) t))
(TmApplication t1 t2) -> (TmApplication (walk c t1) (walk c t2))
termSubst :: Int -> Term -> Term -> Term
termSubst j s t = walk 0 t
where walk c t = case t of
(TmVariable x n) -> if x == (j+c) then termShift c s
else (TmVariable x n)
(TmAbstraction x t) -> (TmAbstraction x (walk (c+1) t))
(TmApplication t1 t2) -> (TmApplication (walk c t1) (walk c t2))
termSubstTop :: Term -> Term -> Term
termSubstTop s t = termShift (-1) (termSubst 0 (termShift 1 s) t)
eval1 :: Context -> Term -> Maybe Term
eval1 ctx (TmApplication (TmAbstraction x t) v) | (isVal ctx v) = Just (termSubstTop v t)
eval1 ctx (TmApplication t1 t2) | (isVal ctx t1) = (eval1 ctx t2) >>= (\t2' -> Just (TmApplication t1 t2'))
| otherwise = (eval1 ctx t1) >>= (\t1' -> Just (TmApplication t1' t2))
eval1 ctx _ = Nothing
eval :: Term -> Term
eval t = case (eval1 t) of
(Just t') -> eval t'
Nothing -> t
Name:
Anonymous2014-02-11 17:53
##starts program
Pstart;
print = "welcome to the main menu! do you want to lambda?";
menu {4, if(not_pick; then return EMPTY)}(
(YES; then lambda);(NO; then not_pick);(INFO; then info);(EXIT; then not_pick);
escapefunction(not_pick AND info); end;);
{info}(print = "a program to labmda, made under GNU and BSD. 2014";end;);
Pend.
eval :: Context -> Term -> Term
eval ctx t = case (eval1 ctx t) of
(Just t') -> eval ctx t'
Nothing -> t
Name:
Anonymous2014-02-11 19:05
>>4
great job >>5
a little by the books, but ok >>6
will test when i get home >>8
why not just use eval?
Name:
Anonymous2014-02-11 19:31
>>10
Because ahmed-eval evaluates a Lisp object representation of Ahmed Lambda Calculus expressions, but eval evalutes Lisp representations of Lisp programs.
>>5,9
How are you novices not ashamed to post your novice programs in your novice friendly language in a forum for expert programmers? You weren't raised well.
type exp = Sym of string | Lam of string * exp | App of exp * exp
type den = Closed of string * exp * (string * den) list
let rec eval' env = function
| Sym x -> List.assoc x env
| Lam (x, e) -> Closed (x, e, env)
| App (f, x) -> match eval' env f with
| Closed (name, body, env') -> eval' ((name, eval' env x) :: env') body
let eval = eval' []
or if you're an ANUSEXPERT PROGRAMMER:
type cddaar = [ `Cdraadaarda of string ]
type cdadar = [ cddaar | `Cdraaddrrda of cddaar * cdadar | `Cdraadarrda of cdadar * cdadar ]
type cdaadr = ConsMyAnus of ([`Cdraaddrrda of cddaar * cdadar] * (cddaar * cdaadr) list)
let rec eval' env = function
| `Cdraadaarda _ as x -> List.assoc x env
| `Cdraaddrrda _ as x -> ConsMyAnus (x, env)
| `Cdraadarrda (f, x) -> match eval' env f with
| ConsMyAnus (`Cdraaddrrda (caar, cadr), cdr) -> eval' ((caar, eval' env x) :: cdr) cadr
let eval = eval' []
let lam x b : cdadar = `Cdraaddrrda (x, b)
let app f x : cdadar = `Cdraadarrda (f, x)
let y = `Cdraadaarda "y"
let x = `Cdraadaarda "x"
let z = `Cdraadaarda "z"
let w = `Cdraadaarda "w"
let ya = eval (app (app (lam x (lam y x)) (lam w w)) (app (lam x x) (lam z z)))
Name:
Anonymous2014-02-15 21:04
[code]
type
TKind = enum sym, cons, null, lam
TCons[T] = tuple[car,cdr: ref T]
TREnv = seq[TLispObj] # runtime environment
TCEnv = seq[string] # compile-time environment
TLispFunc = proc(env:TREnv): TLispObj
TLambdaVal = tuple[env: TREnv, body: TLispFunc, print_rep: string]
TLispObj = object
case kind*: TKind
of sym: symval: string
of cons: consval: TCons[TLispObj]
of null: nil
of lam: funcval: TLambdaVal
I drew you a picture of lambada calcius. I'm pretty sure this is what it looks like. ,,,`````Vò---^
<[u]```[/u],,___| /_,vvvv
w w `[u]'^^[/u],
,--,
( )
`--'
Name:
Anonymous2014-02-17 17:58
wait, fuck
[pre]
,,,`````Vò---^
<```,,___| /_,vvvv
w w `'^^,
,--,
( )
`--'
[/pre]
Name:
Anonymous2014-02-17 17:59
Help, how do i prog?
Name:
Anonymous2014-02-17 18:03
,,,`````Vò---^
<```,,___| /_,vvvv
w w `'^^,
,--,
( )
`--'
I'll figure this out.