Jump to content

[0.24] Automated Guidance Computer


bassgojoe

Recommended Posts

  • 1 month later...

bassgojoe, what's the correct syntax for defining a function that does NOT take a parameter? (In this case I'm trying for a function that returns #t once and #f ever after, for example for the initial launch staging.)

(define (func junk) ...) works, but needs a junk value in the call.

(define (func) ...) complains that I need to add an argument.

(define func ...) does not work, from all I see it thinks 'func' is going to be a variable.

Common Lisp sidesteps that issue by having a 'defun' and 'defvar' (and 'defmacro', 'defconstant', 'defclass', 'defmethod', 'defparameter' and so on).

Link to comment
Share on other sites

The fact that (define (func) ...) doesn't work is probably a bug. But you can work around it:

(define (f x y ...) exp) is actually just converted into (define f (lambda (x y ...) exp))

So if you want to define a function without any variables you should be able to use the lambda syntax directly:

(define func (lambda () exp))

Link to comment
Share on other sites

(begin
(define AGC.Status (list 1 88))
)

works.

(begin
((lambda ()
(define AGC.Status (list 1 88))
))
)

does not work. It behaves as if AGC.Status was never defined, though introducing errors in the define line are detected and seem to indicate that the line is executed. Changing to some other command (e.g. a let with an if and an action group) also shows that the code is executes.

Since AGC.Status is about the only flexible output possibility (outside defining variables and dumping them by pressing "Debug") this does hamper code testing.

Link to comment
Share on other sites

For e.g. calculating atmospheric density[1] at height raising Euler's Number to (/ -12502 5000) is needed. Also important is the natural logarithm.

[1] for finding terminal velocity. For intelligent speed control on the lower part of ascent, for example.

It would be good to be able to use the common trigonometric functions.

Link to comment
Share on other sites

(begin
(define AGC.Status (list 1 88))
)

works.

(begin
((lambda ()
(define AGC.Status (list 1 88))
))
)

does not work.

For the variable to exist in the parent scope you need to define it there and then set it inside your function:


(begin
(define AGC.Status 0)
((lambda ()
(set! AGC.Status (list 1 88))
))
)

Edited by bassgojoe
Link to comment
Share on other sites

For the variable to exist in the parent scope you need to define it there and then set it inside your function

Adjusting mental model from "Magic variable that pre-exists, but must be written to with 'define' instead of 'set!'" to "If a top level AGC.Status variable is made to exist at the end of the pass (once per tick) through the program, the content is also shown in the output field --- this is the only magic. The variable does not exist if you don't create it."

Transcendental functions have been added: https://github.com/joevenzon/kerbal-agc/commit/33d464409d28d6d7e1c61049a3cededcbb5033fa

and I updated the README.md with their names.

Cool! Thank you! Now I only need to manage to wrangle monodevelop into submission ... and my next mission under computer control can start.

Link to comment
Share on other sites

  • 2 weeks later...
This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...