Theodor Berza
Theodor Berza

Reputation: 583

Racket Keyword used as an expression

I try to write a program that adds in the source code the string "hello world". The name of the file in source.rkt. It gives me this error:

source.rkt:6:31: #%datum: keyword used as an expression in: #:mode
  #(118 6)

This is the code:

#lang racket

(provide (all-defined-out))

(define out (open-output-file "source.rkt"
                             [#:mode 'text               
                              #:exists 'can-update]))

(write "hello world" out)

(close-output-port out)

Upvotes: 3

Views: 484

Answers (1)

Sorawee Porncharoenwase
Sorawee Porncharoenwase

Reputation: 6502

The brackets are not literals. They mean optional. Therefore, the correct syntax is:

(define out (open-output-file "source.rkt"
                              #:mode 'text               
                              #:exists 'can-update))

Upvotes: 7

Related Questions