rkt-pythonize
1 Supported Features
2 Syntax
3 Default Primitives
4 Examples
5 Functions
current-primitives
L
LS
compile-scheme-code
parse-L
unparse-L
parse-LS
unparse-LS
9.1

rkt-pythonize🔗ℹ

zhanghao

 (require rkt-pythonize) package: rkt-pythonize

My Scheme2Python Compiler. The interpreter is tested against CPython(3.10-3.14), PyPy(3.10-3.11) and mypy 1.18.

1 Supported Features🔗ℹ

  • Named let

  • let/cc

  • TCO(Tail-Call Optimization)

  • Stream

  • Inlining

  • Partial evaluation

  • Scripting

2 Syntax🔗ℹ

(define-language
 L13
 (entry Expr)
 (terminals (arity (ar)) (name (nm)) (constant (c)) (variable (x)) (datum (d)))
 (Expr
  (e body)
  (throw e)
  (with-handler e body ...)
  (cond (e0 e1 ...) ... el)
  (stream-cdr e)
  (stream-car e)
  (stream-cons e0 e1)
  (#%scm-procedure e ar)
  (#%vm-procedure e ar)
  (=>! e0 nm* ... nm0 e1)
  (=> e0 nm* ...)
  (if e0 e1)
  (if e0 e1 e2)
  (or e* ...)
  (and e* ...)
  (let x ((x* e*) ...) body* ...)
  (letrec ((x e) ...) body ...)
  (let ((x e) ...) body ...)
  c
  (let/cc x body* ...)
  (lambda (x* ...) body* ...)
  x
  (begin e* ...)
  (set! x e)
  'd
  (closure d0 d1 e)
  (e0 e* ...))
 (Argument (a) x (box x))
 (Else (el) (else e* ...)))
(define-language
 LS
 (entry Script)
 (terminals (arity (ar)) (name (nm)) (constant (c)) (variable (x)) (datum (d)))
 (Expr
  (e body)
  (throw e)
  (with-handler e body ...)
  (cond (e0 e1 ...) ... el)
  (stream-cdr e)
  (stream-car e)
  (stream-cons e0 e1)
  (#%scm-procedure e ar)
  (#%vm-procedure e ar)
  (=>! e0 nm* ... nm0 e1)
  (=> e0 nm* ...)
  (if e0 e1)
  (if e0 e1 e2)
  (or e* ...)
  (and e* ...)
  (let x ((x* e*) ...) body* ...)
  (letrec ((x e) ...) body ...)
  (let ((x e) ...) body ...)
  c
  (let/cc x body* ...)
  (lambda (x* ...) body* ...)
  x
  (begin e* ...)
  (set! x e)
  'd
  (closure d0 d1 e)
  (e0 e* ...))
 (Argument (a) x (box x))
 (Else (el) (else e* ...))
 (Definition (def) (define x e))
 (Statement (st) def e)
 (Script (sc) (#%script-begin st ...)))

3 Default Primitives🔗ℹ

'(print apply make-procedure make-python-procedure vm-apply dynamic-require get-attribute set-attribute! raise error none ! @ ? <! length set-box! unbox box cons car cdr null not equal? eq? + - * / quotient modulo negate > < is-a? object-type stream-type box-type closure-type exn-type str-type int-type linked-list-type)

4 Examples🔗ℹ

5 Functions🔗ℹ

parameter

(current-primitives)  (listof symbol?)

(current-primitives primitives)  void?
  primitives : (listof symbol?)

language

L : any/c

language

LS : any/c

compiler

(compile-scheme-code code    
  dest    
  [#:raw? raw?    
  #:script? script?])  any
  code : any/c
  dest : path-string?
  raw? : boolean? = #f
  script? : boolean? = #f

parser

(parse-L code)  any

  code : any/c

unparser

(unparse-L s-exp)  any

  s-exp : any/c

parser

(parse-LS code)  any

  code : any/c

unparser

(unparse-LS s-exp)  any

  s-exp : any/c