Andrew Lentvorski wrote:
The veracity of your post is lessened greatly by the lack of code.

You didn't ask for code. Indeed, it seems clear you didn't even give a decent description of your requirements. :-)

This is especially true since I'm having trouble thinking of a way to make *anything* read-only in Forth at a syntax level.

Uh, both colon words and literals are implemented in FORTH and are read-only at the syntax level. Write a word like "bind" that takes a value on the stack and a name afterwards, and that's your assignment. If you try to bind a name that already exists, bind can give you whatever kind of error you want. Invoking the name returns the value it's bound to. Invoking the name with ".next" tacked on returns the value that's next. Etc.

And I can't really think of a way to override "set" properly in Tcl either in normal use or with an object system like [incr Tcl]. Hopefully Lan will weigh in here.

proc set {args} { ... }
Or, for that matter,
proc proc {args} { ... }

Wrap it in code that when you run [set x y] your version of [set] looks to see if "x" is actually in some specific namespace, and if it is, it checks to see if the value is already bound, and if it is, it throws an error. The same sort of thing "array set" does, for example, when it finds a non-array variable.

If this isn't what you mean, then you'd need to clarify your requirements.

And, Ada, IIRC, has a const-like declaration, but lacks the ability to do dynamic assignment without declarations like Python.

Make it a limited type. Or even a package type for that matter.

No, Ada doesn't have the ability to do dynamic assignment without declarations. Neither does C or C++, which you said "can do this". So I'm not really sure what you're after here.

It's seems easy to do one or the other of const static declarations or dynamically assignable typing. It doesn't seem like many languages do both.

Seems like FORTH could, LISP probably could (using appropriate macros), and Tcl could. Are you also throwing in the requirement that all these values have to look like normal variables to some parts of the code? I.e., are you suggesting that a name bound once has to look the same as a rewritable name, can't need a declaration, but has to be detected as being multiply assigned before execution starts? Sounds like a tall order that C++ doesn't even meet.

When do you want to detect a reassignment of a variable? When you attempt to reassign it? Or when you compile your code? If the former, Ada and FORTH and Tcl and can all do it pretty easily. If the latter, C++ can't do it and you're probably looking at solving the halting problem unless you only allow one assignment in the entire static text of the program.

I suspect, now that I think about it, that most any functional language would do you up well too.

--
Darren New / San Diego, CA, USA (PST)

--
KPLUG-LPSG@kernel-panic.org
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg

Reply via email to