Hey guys,
I'm trying to get the name and latest value from a variable, and write a variable declaration in a new file with this information. Like so:
module1.nim var name = "Leon" name = "Blane" # I want this value, not the value it was instantiated with
module2.nim var name = "Blane" # this needs to be taken from module1.nim
I've been playing around with templates and macros without success. Any ideas?
# module1:
var name* = "Leon"
name = "Blane"
# module2:
from moduel1 import nil
var name = moduel1.name
Thanks, I wasn't clear enough though. I need to do this programmatically. I have a Jupyter Notebook-like IDE I'm building.
It uses embedded nimscript, passing data (module1 scenario) to the backend for execution. What I'm trying to include now is the ability to make a variable, procedure, and type from a previous cell (module) available to the next. So far I have an expose macro that will handle this for types and procedures, but not for variables.
The idea (currently) is to have an intermediary file that gets written to / read from, storing each cells "exposed" procs, types, variables for a single session. This will be concatenated with the string containing the code, all executed in the VM.
I hope this makes sense. I'm running off like 3 hours sleep I'm loopy as hell lol
Simple macro to get symbol name.
macro getSymbolName(x: untyped): string = x.toStrLit
I'm not sure if I get what you want for getting the latest value.
Personally, I'd say that only exported symbols are usable in future cells, and then I'd load each cell in its own module and have each module automatically import all previous modules/cells.
Advantages:
You could potentially use Nim devel and import {.all.} if you really want to access unexported symbols using the same approach. I'm not positive this would work, but it seems like it should.
I'd like to use nim secret as the REPL for the IDE but I get stuck trying to print out the output stream (the process is called via startProcess and I have two variables- 1 for the input stream 1 for the output)
Is there a good source for handling like... sending and receiving messages to/from this thing??