sourceextensions/hello/lib/Hello.xtl

1⍝# Hello.xtl -- the facade of the hello extension, the smallest X_eTaL 2⍝# native extension: each function proves one thing about the boundary. 3⍝# Import: "hx:" u_se< "Hello" 4⍝# Run with xetal-x (xetal-x --ext DIR puts this directory on XETAL_PATH). 5⍝# Each line below is a native function's signature; the binding macro 6⍝# (lib/Ffi.xtlm, docs/ffi-macro.md) writes the facade function from it. 7 8ᶠᶠⁱ⁼u̲se< "Ffi" 9 10⍝# The answer, 42. 11"a_nswer : unit -> int" ᶠᶠⁱb̲ind< "hello/answer"
ᶠᶠⁱb̲ind< expands to
ˡa̲nswer ← { @ →
  f̲loor f̲irst n̲umbers ⎕N̲GET "ext:hello/answer"
}
12⍝# Left plus right, added natively. 13"a_dd : float float -> float" ᶠᶠⁱb̲ind< "hello/add"
ᶠᶠⁱb̲ind< expands to
ˡa̲dd ← { a b →
  pa ← (f̲ormat r̲avel f̲loat a) ⎕N̲PUT "ext:hello/add?float=" c̲at f̲ormat s̲hape a
  pb ← (f̲ormat r̲avel f̲loat b) ⎕N̲PUT "ext:hello/add?float=" c̲at f̲ormat s̲hape b
  f̲irst n̲umbers ⎕N̲GET "ext:hello/add"
}
14⍝# The text in upper case (Unicode). 15"s_hout : text -> text" ᶠᶠⁱb̲ind< "hello/shout"
ᶠᶠⁱb̲ind< expands to
ˡs̲hout ← { a →
  pa ← a ⎕N̲PUT "ext:hello/shout?text"
  ⎕N̲GET "ext:hello/shout"
}
16⍝# The sum of every element of a numeric array. 17"s_um : float -> float" ᶠᶠⁱb̲ind< "hello/sum"
ᶠᶠⁱb̲ind< expands to
ˡs̲um ← { a →
  pa ← (f̲ormat r̲avel f̲loat a) ⎕N̲PUT "ext:hello/sum?float=" c̲at f̲ormat s̲hape a
  f̲irst n̲umbers ⎕N̲GET "ext:hello/sum"
}
18⍝# A numeric array sent across and back: the same values and shape. 19"e_cho : float -> floats" ᶠᶠⁱb̲ind< "hello/echo"
ᶠᶠⁱb̲ind< expands to
ˡe̲cho ← { a →
  pa ← (f̲ormat r̲avel f̲loat a) ⎕N̲PUT "ext:hello/echo?float=" c̲at f̲ormat s̲hape a
  v ← n̲umbers ⎕N̲GET "ext:hello/echo"
  (f̲loor n̲umbers ⎕N̲GET "ext:hello/echo?shape") r̲eshape v
}
20⍝# Always fails: a native error is an X_eTaL error. 21"f_ail : unit -> int" ᶠᶠⁱb̲ind< "hello/fail"
ᶠᶠⁱb̲ind< expands to
ˡf̲ail ← { @ →
  f̲loor f̲irst n̲umbers ⎕N̲GET "ext:hello/fail"
}
22⍝# Always panics inside Rust: contained, reported as an X_eTaL error. 23"p_anic : unit -> int" ᶠᶠⁱb̲ind< "hello/panic"
ᶠᶠⁱb̲ind< expands to
ˡp̲anic ← { @ →
  f̲loor f̲irst n̲umbers ⎕N̲GET "ext:hello/panic"
}
24 25⍝# The native package behind these functions (a literal l: name also 26⍝# makes this file a library to xetal type: ask E7). 27ˡpackage ← "hello"