Gian Medri wrote:
> I am using kfiles in j602.
> I need to lock single component.
> Is it possible and how?
Funny, I thought I wrote a reply to this question yesterday, but now I can
find no trace of it. Some neurons must be on the fritz after Santacon.
Anywho.
I don't think you can lock specific components in a kfile. What you can
do, however, is lock the file (contents) and/or the name when it's in the
session.
For the former, locking the file, segregate the components you want "locked
down" into a dedicated kfile, write them, then set the read-only bit on
the file. Not sure how to set file attributes from within J off the top of
my head, but if you're on Linux or a Mac, you might be able to use 2!:0
(host command, e.g. 2!:0 'chmod a=r ',filename). Host commands don't work
on Windows (try the task script [2]).
For the latter, locking the name (or rather, than name/value association)
when it's in the session, you can use my old "Single Assignment J" (SAJ)
script [1]. Unfortunately, some of the (undocumented) tools it relies
upon have changed since I first introduced it, so now you can only "lock"
nouns. Verbs, adverbs, and conjunctions can no longer be locked (until
someone rolls back the change).
Another option is to do both: make the file *and* the name read-only. You
can achieve this by using mapped files in place of kfiles. Of course,
mapped files also only apply to nouns, but they have several benefits,
including automatic persistence, enhanced performance, and instant
shareability between J sessions. And, as I said, you can mark a mapped
noun (JMF) as read-only, which applies to both the name and the file (the
name-locking is actually the same mechanism as I use in SAJ). Drawbacks
include having to manage noun and non-noun names separately (JMF vs
kfiles) as well a 1-to-1 mapping between JMF files and nouns (not strictly
true, but doing anything else is inconvenient enough to treat it as a
drawback).
If mapped files interest you, check out the lab "Mapped Files".
-Dan
[1] Single-assignment J, "SAJ":
http://www.jsoftware.com/jwiki/DanBron/Temp/SingleAssignmentJ
[2] Task script for spawning external processes on Windows and other OSes:
http://www.jsoftware.com/help/user/script_task.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm