1. Suggestion for dir()

Instead of returning -1 if the file is not found,
isn't it better to return {} ?

I have had many errors, just because I forgot to check if it is an
atom or not, in such lines:

  dd = dir("c:\\*.bmp") --where no *.bmp files on c:\
  for i = 1 to length(dd) do
      something("c:\\" & dd[i][D_NAME])
  end for

and it will crash on length().

new topic     » topic index » view message » categorize

2. Re: Suggestion for dir()

That would break quite a few programs.

Why not edit your version of file.e, and change this:

global function dir(sequence name)
-- returns directory information, given the name
-- of a file or directory. Format returned is:
-- {
--  {"name1", attributes, size, year, month, day, hour, minute, second},
--  {"name2", ...                                                     },
-- }
	return machine_func(M_DIR, name)
end function

to this:

global function dir(sequence name)
-- returns directory information, given the name
-- of a file or directory. Format returned is:
-- {
--  {"name1", attributes, size, year, month, day, hour, minute, second},
--  {"name2", ...                                                     },
-- }
	object aku_saya
	aku_saya = machine_func(M_DIR, name)
	if atom(aku_saya) then
		aku_saya = {}
	end if
	return aku_saya
end function

Or is there some reason that this is undesirable for you?

On Sat, May 31, 2003 at 09:20:09PM +0700, aku saya wrote:
> 
> 
> Instead of returning -1 if the file is not found,
> isn't it better to return {} ?
> 
> I have had many errors, just because I forgot to check if it is an
> atom or not, in such lines:
> 
>   dd = dir("c:\\*.bmp") --where no *.bmp files on c:\
>   for i = 1 to length(dd) do
>       something("c:\\" & dd[i][D_NAME])
>   end for
> 
> and it will crash on length().
> 
> 
> 
> TOPICA - Start your own email discussion group. FREE!
> 
> 

-- 
 /"\  ASCII ribbon              | http://www.geocities.com/jbrown1050/
 \ /  campain against           | Linux User:190064
  X   HTML in e-mail and        | Linux Machine:84163
 /*\  news, and unneeded MIME   |

new topic     » goto parent     » topic index » view message » categorize

3. Re: Suggestion for dir()

you wouldn't even need to alter file.e, just remake the functions, like
this:

function old_dir(sequence path)
    return dir(path)
end function

function dir(sequence path)
object dd
    dd = old_dir(path)
    if atom(dd) then
        return {}
    else
        return dd
    end if
end function

~Greg

new topic     » goto parent     » topic index » view message » categorize

4. Re: Suggestion for dir()

Hello aku saya:

> Wow, thanks very much Greg and Jbrown!
> I didn't realize that dir() 
> is not a built-in routine.

You can do that trick below 
with *built-in routines* too.

You can not rename this way *just key words*:
for, to, global, function ... etc - blue words,
not magenta - about 30 English words.

See for example my "Russian Toolkit"
in The Archive.
 
There are all Russian analogs for
built-in and standard RDS lib routines
for those interpreters with non-limited
alphabet. In that package, there is ed.ex
rewrote in Russian. Try that mumbo/jumbo,
works ok for me.

I asked Rob for the loading keywords 
(Russian, Malay, Chinese ...) years ago, 
he doesn't want, exquisite English boy blink

Regards,
Igor Kachan
kinz at peterlink.ru

> G> you wouldn't even need to alter file.e, 
> G> just remake the functions, like
> G> this:
> 
> G> function old_dir(sequence path)
> G>     return dir(path)
> G> end function
> 
> G> function dir(sequence path)
> G> object dd
> G>     dd = old_dir(path)
> G>     if atom(dd) then
> G>         return {}
> G>     else
> G>         return dd
> G>     end if
> G> end function
> 
> G> ~Greg

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu