Post Reply 
Naive question re: RCL variables in 42S & related
10-15-2024, 01:26 AM (This post was last modified: 10-15-2024 02:27 AM by Thomas Klemm.)
Post: #16
RE: Naive question re: RCL variables in 42S & related
(10-14-2024 06:16 PM)Thomas Klemm Wrote:  If you like Lisp, you can try Clojure or Hy.

Some related links:
And here's an example of disassembled byte code from Hy:

[Image: attachment.php?aid=6050]

Which can then be translated to RPN/FOCAL:
Code:
LBL "CIRCLE"
STO 00 ; r
RDN
PI
RCL 00 ; r
2
Y↑X
*
RTN



Addendum: This is the result of the current version 1.0.0 in try-hy:
Code:
import hy
------------------------------
Hy 1.0.0 (Afternoon Review) using CPython(main) 3.12.1 on Emscripten
=> (import math [pi])
from math import pi
None
------------------------------
=> (defn circle [r] (* pi (** r 2)))
def circle(r):
    return pi * r ** 2
None
------------------------------
=> (import dis [dis])
from dis import dis
None
------------------------------
=> (dis circle)
dis(circle)
------------------------------
  1           0 RESUME                   0
              2 LOAD_GLOBAL              0 (pi)
             12 LOAD_FAST                0 (r)
             14 LOAD_CONST               1 (2)
             16 BINARY_OP                8 (**)
             20 BINARY_OP                5 (*)
             24 RETURN_VALUE

Conclusion: While the generated byte code for Python 3.12 is different it can still be easily translated to RPN/FOCAL.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Naive question re: RCL variables in 42S & related - Thomas Klemm - 10-15-2024 01:26 AM



User(s) browsing this thread: 6 Guest(s)