Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example with lambda enumeration in jetta #758

Merged
merged 4 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions python/sandbox/jetta/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ def jetta_unwrap_atom(j_space_a: Atom, code_a: Atom,
"""
j_space = j_space_a.get_object().value
if isinstance(code_a, GroundedAtom):
code = code_a.get_object().value
else:
code = repr(code_a)
code_a = code_a.get_object().value
if not isinstance(code_a, str):
code_a = repr(code_a)
url = url_a.get_object().value
try:
result = jetta(j_space, code, url)
result = jetta(j_space, code_a, url)
return [Atoms.UNIT if result is None else ValueAtom(result)]
except JettaServerError as e:
return _err_msg(code, e)
return _err_msg(code_a, e)
#return [E(S('Error'), ValueAtom(code),
# E(S('JettaCompileError'), ValueAtom(str(e))))]

Expand Down
34 changes: 34 additions & 0 deletions python/sandbox/jetta/enum_lambda.metta
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
!(import! &self compile)

!(bind! &jspace (new-jetta-space))

!(jetta &jspace "
(: err (-> Int Int Int))
(= (err $a $b)
(* (- $a $b) (- $a $b)))
(: calc_err (-> (-> Int Int) Int))
(= (calc_err $f)
(+ (err ($f 1) 8)
(err ($f 2) 13)
(err ($f 5) 40)
(err ($f 10) 125)
)
")

(= (bin) 0)
(= (bin) 1)
(= (num Z) (bin))
(= (num (S $x))
(+ (* 2 (num $x)) (bin)))
(= (num8) (num (S (S (S Z)))))

(= (rnd-square)
(\ ($x)
(+ (* (bin) (* $x $x))
(+ (* (num8) $x) (num8))))
)

!(let $f (rnd-square)
(if (== (jetta &jspace (calc_err $f)) 0)
$f
Empty))
4 changes: 2 additions & 2 deletions python/sandbox/jetta/test_lambda.metta
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
(: goo (-> Int Int Int))
(= (goo $x $y) (* $x $y))"
)
; NOTE: doesn't work for now
(assertEqual
; passing a function
!(assertEqual
(jetta &jspace "(foo 2 3 goo)")
6)
; checking that passing lamdas directly works
Expand Down
5 changes: 3 additions & 2 deletions python/sandbox/snet/snet_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def import_service(org_id, service_id,
eth_rpc_endpoint=os.getenv("ETH_RPC_ENDPOINT"),
email=os.getenv("SNET_EMAIL", "[email protected]"),
free_call_auth_token_bin=os.getenv("FREE_CALL_AUTH_TOKEN_BIN", None),
free_call_token_expiry_block=os.getenv("FREE_CALL_TOKEN_EXPIRE_BLOCK", 20048217)
free_call_token_expiry_block=os.getenv("FREE_CALL_TOKEN_EXPIRE_BLOCK", 20685151)
):
# group_name="default_group"
config = {
Expand All @@ -28,9 +28,10 @@ def import_service(org_id, service_id,
"service_id": service_id,
"identity_name": "test",
"identity_type": "key",
# "force_update"=True
}
snet_sdk = sdk.SnetSDK(config)
service_client = snet_sdk.create_service_client(org_id, service_id)#, group_name)
service_client = snet_sdk.create_service_client()#, group_name)
return ServiceCall(service_client)

@register_atoms()
Expand Down
Loading