Jump to content

Compile-time calculation: Difference between revisions

Add Racket entry
(removed REXX from omit from as REXX as compile time calculations. -- ~~~~)
(Add Racket entry)
Line 661:
could on a x86 be complied to
<pre>MOV dword [v_a],3628800</pre>
 
=={{header|Racket}}==
 
Racket, like most Lisp descendants, allows arbitrary code to be executed at compile-time.
 
<lang lisp>
#lang racket
 
;; Import the math library for compile-time
;; Note: included in Racket v5.3.2
(require (for-syntax math))
 
;; In versions older than v5.3.2, just define the function
;; for compile-time
;;
;; (begin-for-syntax
;; (define (factorial n)
;; (if (zero? n)
;; 1
;; (factorial (- n 1)))))
 
;; define a macro that calls factorial at compile-time
(define-syntax (fact10 stx)
#`#,(factorial 10))
 
;; use the macro defined above
(fact10)
</lang>
 
=={{header|REXX}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.