I was wondering if you're allowed to call another program you made to do work in a new program you are about to make in scheme, or would I have to copy and paste all the code from the previous program, though I can do this and make my life simple, I'm wondering if there is a more sophisticated elegant way to import in scheme r5rs.
;; Here is an example of what I mean
;; for example I have a file name add.scm which adds 2 numbers
;; now I want to make a new function that squares the numbers
;;is there a way I can do something like this
#lang add.scm as add
;;and use it here like so
(define (square x)
(* x x))
(square add)
;;where add already returns a value
This may seem like a silly piece of code, but this is the best pesudo code I can give, if the example needs more editing to understand please let me know, thank you.
If I understand your question, you have this module named
add.scm:and you want to write a new module that gets the value that the
add.scmmodule prints out, bind it to a variable, and use it in a computation, like this:No, there is no easy way to do that. It's possible, by using
dynamic-requireor a subprocess to run the module, capturing the output and thenreading it to get the value, but that's an awful, complicated, brittle way to do things.In Racket, a better approach would be for
add.rktto define and export a variable and have amainsubmodule that prints the value:Then you can use
(require "add.rkt")from another module to getxto use in computations, and if you runadd.rktas a program (for example, withracket add.rkt), then it prints the value.