Evaluating a file from within a file?

27 views
Skip to first unread message

Tim Roberts

unread,
Apr 19, 2016, 2:54:27 AM4/19/16
to Extempore
As my project becomes larger, I'd like to be able to evaluate everything within the file I'm working in.
How would I go about evaluating an entire file from a line within the file?

Ben Swift

unread,
Apr 19, 2016, 3:22:48 AM4/19/16
to extemp...@googlegroups.com
Hi Tim

`sys:load` can be used to eval any file - not just the builtin library
ones. So maybe give that a go?

Cheers,
Ben

Tim Roberts

unread,
Apr 19, 2016, 9:38:29 PM4/19/16
to Extempore, b...@benswift.me
Yep, so I evaluated this line from within the TSM.xtm file.

(sys:load "TSM/TSM.xtm")

And the terminal begins printing:

ALLOCATED NEW MEMORY: new_total(1600000)

ALLOCATED NEW MEMORY: new_total(1700000)

ALLOCATED NEW MEMORY: new_total(1800000)

ALLOCATED NEW MEMORY: new_total(1900000)

ALLOCATED NEW MEMORY: new_total(2000000)

ALLOCATED NEW MEMORY: new_total(2100000)

ALLOCATED NEW MEMORY: new_total(2200000)

ALLOCATED NEW MEMORY: new_total(2300000)

etc.


If I run the command from another location it all works correctly.

Is there a way to evaluate the entire file from inside it.  If not, that's fine and I'll move towards separate files.

Toby Gifford

unread,
Apr 19, 2016, 10:00:40 PM4/19/16
to extemp...@googlegroups.com
Are you using Emacs? If so just select the whole file and evaluate the region (control-c-r)


--
You received this message because you are subscribed to the Google Groups "Extempore" group.
To unsubscribe from this group and stop receiving emails from it, send an email to extemporelan...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Toby Gifford

unread,
Apr 19, 2016, 10:38:00 PM4/19/16
to extemp...@googlegroups.com
If you really want to load the file from a saved line within itself, you could do something like this with include guards (good idea for libraries anyway) and a couple of lines beyond the include guard, that you would have to evaluate in reverse order (so two evaluations rather than just one). Probably there's some tricky way of making it just one line with macros.

;; Open include guard
(if (and (defined? '*xtmlib-TCM-loaded*) *xtmlib-TCM-loaded*)
    (sys:load-escape "TCM library already loaded"))
(define *xtmlib-TCM-loaded* #f)

;;;;;;;; code goes here ;;;;;;;
(print "Callooh Callay, oh Frabjous Day!")

;; Close include guard
(set! *xtmlib-TCM-loaded* #t)


;; Manual loading code: evaluate second line and then evaluate first line
(sys:load "path/to/TCM.xtm")
(set! *xtmlib-TCM-loaded* #f)


On Wed, Apr 20, 2016 at 11:38 AM, Tim Roberts <zyg...@gmail.com> wrote:

Tim Roberts

unread,
Apr 20, 2016, 9:35:20 PM4/20/16
to Extempore
Yeah cool.  That's something that I'll definitely have to do towards the end of the project.

The highlighting thing works within Atom too as I have discovered.  When I was first starting out, I couldn't get anything to compile because I was highlighting it, but that's been fixed now.  Could have been an older windows build issue.
Reply all
Reply to author
Forward
0 new messages