如何从windows运行已编译的racket程序

如何从windows运行已编译的racket程序,racket,Racket,该程序通过引用主函数并传递任何参数在drRacket中运行。如何从命令行或单击.exe文件执行此操作?主要功能如下: (define (worm-main ct) (big-bang (make-wormState (init-worm INIT-WORM-SEGS START-POSN) "r" (food-create (make-posn 99999 99999))) [to-draw render] [on-key navigate] [on-tick mov

该程序通过引用主函数并传递任何参数在drRacket中运行。如何从命令行或单击.exe文件执行此操作?主要功能如下:

(define (worm-main ct)
  (big-bang (make-wormState (init-worm INIT-WORM-SEGS START-POSN) "r" (food-create (make-posn 99999 99999)))
    [to-draw render]
    [on-key navigate]
    [on-tick move ct]
    [stop-when end-chk? final-scene]))

我这样调用worm main:-
(worm main 0.2)

我认为您无法从终端调用文件中的函数。或者,在程序中,可以添加输入语句并使用这些参数调用主函数

通过将语言更改为,您可以从终端运行racket程序

#lang racket
例如:

#lang racket
(+ 3 4)
您可以使用(文件名为test.rkt)从命令行运行该命令:

此外,您还可以从Dr.Racket创建一个可执行文件,方法是转到Racket,创建可执行文件

编辑:尝试复制粘贴此文件并创建可执行文件

#lang racket/gui

(require racket/gui/base)

(define frame (new frame% [label "Example"]))

; Make a static text message in the frame
(define msg (new message% [parent frame]
                      [label "No events so far..."]))

; Make a button in the frame
(new button% [parent frame]
         [label "Click Me"]
         ; Callback procedure for a button click:
         [callback (lambda (button event)
                     (send msg set-label "Button click"))])

; Show the frame by calling its show method
(send frame show #t)
; source: https://docs.racket-lang.org/gui/windowing-overview.html#%28part._.Creating_.Windows%29
我相信要看到可执行文件的效果,您的程序必须创建一个新窗口

编辑2: 尝试从命令行编译racket程序,如下所述:

i、 e

在那次跑步之后:

cd compiled
racket name-of-file.zo

从您编写的内容来看,您似乎是从DrRacket的“Racket”菜单中的“createexecutable”项创建了可执行文件。您正在通过键入
(worm main 0.2)
交互区域调用主定义

您的可执行文件无法运行,因为您尚未在定义窗口中添加对主函数的调用。事实上,在创建可执行文件之前,可执行文件只包含文件中的文件

#lang racket/gui

(require racket/gui/base)

(define frame (new frame% [label "Example"]))

; Make a static text message in the frame
(define msg (new message% [parent frame]
                      [label "No events so far..."]))

; Make a button in the frame
(new button% [parent frame]
         [label "Click Me"]
         ; Callback procedure for a button click:
         [callback (lambda (button event)
                     (send msg set-label "Button click"))])

; Show the frame by calling its show method
(send frame show #t)
; source: https://docs.racket-lang.org/gui/windowing-overview.html#%28part._.Creating_.Windows%29

在创建可执行文件之前,必须将调用
(worm main 0.2)
添加到“定义”窗口。

我已创建和可执行文件。但是,当我从windows资源管理器中单击它时,什么也没有发生。当我从命令行运行它时,同样的情况也适用。键入.exe文件的名称。@user1897830请参见编辑;我相信要看到可执行文件的效果,您的程序必须创建一个新窗口。@ssundarr编译的racket程序不需要打开窗口即可运行。当用户1897830试图在命令行中运行可执行文件时,他应该能够看到它打印到stdout的内容。您能告诉我们您是如何创建和调用主函数的吗?这是“如何设计程序”中的蠕虫程序。我只是用时钟的滴答声来调用worm main。ie(蠕虫主机0.2)。
#lang racket/gui

(require racket/gui/base)

(define frame (new frame% [label "Example"]))

; Make a static text message in the frame
(define msg (new message% [parent frame]
                      [label "No events so far..."]))

; Make a button in the frame
(new button% [parent frame]
         [label "Click Me"]
         ; Callback procedure for a button click:
         [callback (lambda (button event)
                     (send msg set-label "Button click"))])

; Show the frame by calling its show method
(send frame show #t)
; source: https://docs.racket-lang.org/gui/windowing-overview.html#%28part._.Creating_.Windows%29