Compile-time calculation: Difference between revisions

Content added Content deleted
(removed REXX from omit from as REXX as compile time calculations. -- ~~~~)
(Add Racket entry)
Line 661: Line 661:
could on a x86 be complied to
could on a x86 be complied to
<pre>MOV dword [v_a],3628800</pre>
<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}}==
=={{header|REXX}}==