Language question -- file = variable ?

Christopher Browne cbbrowne-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org
Tue Aug 16 19:51:26 UTC 2011


On Tue, Aug 16, 2011 at 10:41 AM, William Park <opengeometry-FFYn/CNdgSA at public.gmane.org> wrote:
> Hi all,
>
> Is there a language which (natively or not) treats a filename like a variable in memory?  For example, to increment a counter stored in a file, you would write something like
>         /tmp/counter = /tmp/counter + 1
> which involves both read and write to a file.  If it were normal variable, then it would involve read/write to a memory instead.
>
> Python is the closest I can think of.  But, you need to create a method for read and another method for write.  And, typing more verbose than I would like.

Databases kind of do that, but I'm not sure you were looking for

psql -c "select value from counter_table;" -d mydb

psql -c "update counter_table set value = value + 1;" -d mydb

:-)

Common Lisp is the language where it's most natural to regard
variables in this fashion; it has a formal notion of a "place" [1]
which is "a form which is suitable for use as a generalized
reference."

Using some suitable macro expansion, you could have a "place" that is
backed by whatever sort of storage you might like, so that a "read
reference", my-place would draw the data from storage (where ever that
is) and (incf my-place) would increment it by 1, irrespective of where
it might be.

I don't think I'd be keen to do this with files, per se; if doing this
"in shell," I think I'd rather look at something like MongoDB which
has an increment method, and ask it to increment object values.  That
addresses concurrency issues that would be troublesome with using a
"plain file."

[1]  http://www.lispworks.com/documentation/HyperSpec/Body/05_aa.htm
-- 
When confronted by a difficult problem, solve it by reducing it to the
question, "How would the Lone Ranger handle this?"
--
The Toronto Linux Users Group.      Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists





More information about the Legacy mailing list