nano & mega

J

Jeff Wood

------=_Part_5671_16820029.1125524015189
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

What's up with the funky names ... AND, is there an easy way to just requir=
e=20
all of them ?
I'd like to have all of nano and all of mega easily includable without 400=
=20
separate require statements ( exagerated I know, but still )
j.

--=20
"So long, and thanks for all the fish"

Jeff Wood

------=_Part_5671_16820029.1125524015189--
 
T

Trans

Hi Jeff,

The nice thing about Nano is that you can require just the extension
methods you need, no more, no less. I realize at first that seems
unecessarily burdensome, but in practice it actually proves be quite
natural. And I highly recommend you try to use the library in this
manner. Nonetheless, there is indeed a way to include a many a method
at once.

require 'nano/full'

But be forewarned, this is still experimental. The reason is that not
all of the methods in Nano "play nice" --some have very specific uses.
What I have done is make a list of these particular methods and
"subtract" them from the totality and this is what is in nano/full.rb.
But those lists are not complete/perfected yet, so don't be suprised if
something odd occurs when using 'full'. (And please let me know if you
run across something so I can adjust the lists!) To get more info on
what exactly these methods are try this:

require 'nanosys'

# list of method files in full
NanoSystem.full

# list of methods considered unsafe and not in full
NanoSystem.unsafe

# other methods not in full as a cautionary measure
NanoSystem.noauto

To learn more I recommend the README doc which is included in the
package and is also the front page of the API RDocs on the website
(http://nano.rubyforge.org)

As for Mega, again it is not the standard usage, but you can do:

require 'mega'
autoload_classes

Now whenever you reference a Mega Module it will be automatically
required (w/ a few exceptions.) As of yet I haven't thought of creating
a require file that loads all of them, but I suppose I can. Thanks for
the suggestion.

T.
 
G

Gavin Kistner

[snip] AND, is there an easy way to just require all of them ?
I'd like to have all of nano and all of mega easily includable
without 400
separate require statements ( exagerated I know, but still )

2 minutes looking at the library hierarchy shows:

require 'nano' #Same as require 'nano/base', a common set of
functionality
require 'nano/array' #All the array items
require 'nano/full' #Everything
 
D

Dave Burt

Jeff Wood wrote...
What's up with the funky names ... AND, is there an easy way to just
require
all of them ?
I'd like to have all of nano and all of mega easily includable without
400
separate require statements ( exagerated I know, but still )

In the API docs at nano.rubyforge.org and mega.rubyforge.org, check out the
documentation for the _files_ nano.rb, nano/base.rb (and mega's
corresponding files) to see the list of what's included there.

For example, if you just do:
require 'nano'
or:
require 'nano/base'
you will get all of these for free:
a.. nano/kernel/require_nano
b.. nano/array/to_h
c.. nano/binding/eval
d.. nano/binding/self
e.. nano/binding/caller
f.. nano/comparable/cmp
g.. nano/enumerable/collect_with_counter
h.. nano/enumerable/each_slice
i.. nano/float/round_off
j.. nano/float/round_to
k.. nano/float/round_at
l.. nano/hash/slice
m.. nano/hash/to_h
n.. nano/kernel/fn
o.. nano/kernel/called
p.. nano/kernel/here
q.. nano/matchdata/match
r.. nano/module/basename
s.. nano/nilclass/to_f
t.. nano/nilclass/to_h
u.. nano/object/metaclass
v.. nano/proc/to_method
w.. nano/range/to_r
x.. nano/regexp/to_re
y.. nano/string/blank%3F
z.. nano/string/cmp
aa.. nano/string/to_re
ab.. nano/symbol/not
ac.. nano/time/to_time
Then there's the require_* methods, require_all in particular.

Happy requiring!
Dave
 
T

Trans

Jeff said:
What's up with the funky names ...

Since Ruby methods can have/be punctuation marks, it is necessary to
encode them in order to be compatible with all file systems. I have
used URI escaping so:

: -> %3A
? -> %3F
! -> %21
= -> %3D

etc.
 
J

Jeff Wood

--------------070708050802060700070705
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Dave said:
Jeff Wood wrote...



In the API docs at nano.rubyforge.org and mega.rubyforge.org, check out the
documentation for the _files_ nano.rb, nano/base.rb (and mega's
corresponding files) to see the list of what's included there.

For example, if you just do:
require 'nano'
or:
require 'nano/base'
you will get all of these for free:
a.. nano/kernel/require_nano
b.. nano/array/to_h
c.. nano/binding/eval
d.. nano/binding/self
e.. nano/binding/caller
f.. nano/comparable/cmp
g.. nano/enumerable/collect_with_counter
h.. nano/enumerable/each_slice
i.. nano/float/round_off
j.. nano/float/round_to
k.. nano/float/round_at
l.. nano/hash/slice
m.. nano/hash/to_h
n.. nano/kernel/fn
o.. nano/kernel/called
p.. nano/kernel/here
q.. nano/matchdata/match
r.. nano/module/basename
s.. nano/nilclass/to_f
t.. nano/nilclass/to_h
u.. nano/object/metaclass
v.. nano/proc/to_method
w.. nano/range/to_r
x.. nano/regexp/to_re
y.. nano/string/blank%3F
z.. nano/string/cmp
aa.. nano/string/to_re
ab.. nano/symbol/not
ac.. nano/time/to_time
Then there's the require_* methods, require_all in particular.

Happy requiring!
Dave
Yeah, about 10 seconds after I sent the mail I found that part of the
docs ... Felt like a real goon. Anyways, thanks for putting the
information into the docs, and for shooting me a note.

j.


--------------070708050802060700070705--
 
J

Jeff Wood

--------------060907080102080907010905
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Jeff Wood wrote:




Since Ruby methods can have/be punctuation marks, it is necessary to
encode them in order to be compatible with all file systems. I have
used URI escaping so:

: -> %3A
? -> %3F
! -> %21
= -> %3D

etc.
Wow, I'd say that the punctionation ( with conversion or not ) should
come out of the filenames... the %3A stuff is about as un-user-friendly
as anything I've ever seen.

j.

--------------060907080102080907010905--
 
D

Dave Burt

Jeff said:
Wow, I'd say that the punctionation ( with conversion or not ) should
come out of the filenames... the %3A stuff is about as un-user-friendly
as anything I've ever seen.

You'd have to have a better alternative, and I can't think of one.
Consistent naming's important, and I'd rather not be using interesting
suffixes like "nano/array/rotate_bang".

To ease the pain, instead of:
require 'nano/array/rotate%21'
nano provides:
require 'nanoreq' # or nanosys or nano or nano/base
require_nano 'array/rotate!'
and I presume mega has an analog.

Cheers,
Dave
 
F

Florian Groß

Dave said:
You'd have to have a better alternative, and I can't think of one.
Consistent naming's important, and I'd rather not be using interesting
suffixes like "nano/array/rotate_bang".

Why not? I think I would prefer this over uri escaping. It's also the
convention Ruby uses for the C method names.
 
J

Jeff Wood

--------------050908020109060808000605
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Dave said:
Jeff Wood wrote:



You'd have to have a better alternative, and I can't think of one.
Consistent naming's important, and I'd rather not be using interesting
suffixes like "nano/array/rotate_bang".

To ease the pain, instead of:
require 'nano/array/rotate%21'
nano provides:
require 'nanoreq' # or nanosys or nano or nano/base
require_nano 'array/rotate!'
and I presume mega has an analog.

Cheers,
Dave
well, there are many alternatives.. I'd just have require 'nano/array'
or if you still want the one-by-one functionality ... require
'nano/array/rotate'

ymmv.

j.



--------------050908020109060808000605--
 
J

James Edward Gray II

Dave Burt wrote:



Why not? I think I would prefer this over uri escaping. It's also =20
the convention Ruby uses for the C method names.

Yeah, I have to agree here. I can translate ! to _bang a lot easier =20
than I can think up what the URI escape code is.

James Edward Gray II
 
B

Brian Schröder

Why not? I think I would prefer this over uri escaping. It's also
the convention Ruby uses for the C method names.
=20
Yeah, I have to agree here. I can translate ! to _bang a lot easier
than I can think up what the URI escape code is.
=20
James Edward Gray II
=20
=20
=20[/QUOTE]

It thought nano tweaks include to do the conversion behind the scenes.
Such that you can do

require 'file/exists?'

and require first escapes the ? and then calls the old require.

But I have not used this libs so far.

regards,

Brian

--=20
http://ruby.brian-schroeder.de/

Stringed instrument chords: http://chordlist.brian-schroeder.de/
 
G

Gavin Kistner

--Apple-Mail-1--898838407
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
delsp=yes;
format=flowed

Yeah, I have to agree here. I can translate ! to _bang a lot
easier than I can think up what the URI escape code is.

Bang is pretty easy. What are suggestions for #[]= or #foo versus
#foo= ?
--Apple-Mail-1--898838407--
 
J

Jeff Wood

--------------020005080408080200030605
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Gavin said:
Yeah, I have to agree here. I can translate ! to _bang a lot easier
than I can think up what the URI escape code is.


Bang is pretty easy. What are suggestions for #[]= or #foo versus
#foo= ?

This is what I mean ... why not just package them all based on the class
they use ?

Or maybe extend require to actually allow you to be selective about what
you require from a file .... like a require 'blah=' from 'nano/array' ???

j.


--------------020005080408080200030605--
 
J

James Edward Gray II

Bang is pretty easy.

You're probably right.
What are suggestions for #[]=

Good example. That's a tough one. My best thought:

indexed_equals
or #foo versus #foo= ?

This one seems obvious to me:

foo
foo_equals

To be perfectly honest though, I haven't even downloaded the library
in question, so I have literally no say here. I was just agreeing
that I code remember a word better than a code.

I'll go back to minding my own business now. ;)

James Edward Gray II
 
M

Mauricio Fernández

What are suggestions for #[]=

Good example. That's a tough one. My best thought:

indexed_equals

$ grep "rb_define_.*\[\]" ~/src/ruby/ruby.head/array.c
rb_define_singleton_method(rb_cArray, "[]", rb_ary_s_create, -1);
rb_define_method(rb_cArray, "[]", rb_ary_aref, -1);
rb_define_method(rb_cArray, "[]=", rb_ary_aset, -1);
 
D

David A. Black

Hi --

Yeah, I have to agree here. I can translate ! to _bang a lot easier than I
can think up what the URI escape code is.

Bang is pretty easy. What are suggestions for #[]= or #foo versus #foo= ?

Maybe set_at and foo_set or something like that...?


David
 
T

Trans

While _bang and _equals might be easy to remember, how easy will it be
to remember the many others if they all have some made up name?

array/[]= -> array/aset
hash/[]= -> hahs/hset
proc/* -> proc/compose_op
enumerable/** -> enumerable/cross_op
...

So if you think remebering a handful or two URI escape codes is hard,
think how much harder it would be to remember dozens and dozens of
semi-inconsistent names and the punctuation they correspond-to. I do
not say this w/o inexperience either, since the last version of Facets
actually did just that. It wasn't nice. The escapes look weird but they
quickly become old hat, and are easy enough to look up:

ruby -ruri -e'p URI.escape( "!", "!" )'

But also, you do not need to bother with them at all. There are a
couple of options for forgetting about the whole thing. The simplest
is:

require 'nanosys'

Then you can use the actual punctuation all you want --and w/o any
special require method:

require 'nano/array/[]='

T.
 
F

Florian Groß

Trans said:
But also, you do not need to bother with them at all. There are a
couple of options for forgetting about the whole thing. The simplest
is:

require 'nanosys'

Then you can use the actual punctuation all you want --and w/o any
special require method:

require 'nano/array/[]='

But I'd rather see this based on meaningful, easy to understand naming
scheme under the hood.

Luckily, I have already mapped the special method names. Let me use the
look up table from extract.rb:

{
"+" => "op_plus",
"-" => "op_minus",
"+@" => "op_plus_self",
"-@" => "op_minus_self",
"*" => "op_mul",
"**" => "op_pow",
"/" => "op_div",
"%" => "op_mod",
"<<" => "op_lshift",
">>" => "op_rshift",
"~" => "op_tilde",
"<=>" => "op_cmp",
"<" => "op_lt",
">" => "op_gt",
"==" => "op_equal",
"<=" => "op_lt_eq",
">=" => "op_gt_eq",
"===" => "op_case_eq",
"=~" => "op_apply",
"|" => "op_or",
"&" => "op_and",
"^" => "op_xor",
"[]" => "op_fetch",
"[]=" => "op_store"
}

I'd suggest using foo_bang for foo!, foo_p for foo? and foo_setter for foo=.
 
D

Dave Burt

Florian Groß:
Luckily, I have already mapped the special method names. Let me use the
look up table from extract.rb:
<snip>

Yes, nice. I was disagreeing until I saw this list, now I figure the task of
actually coming up with the names was the barrier.
I'd suggest using foo_bang for foo!, foo_p for foo? and foo_setter for
foo=.

Why foo_p? What's the p? ZenSpider's ZenTest suggests foo_eh. I could see
maybe _q or _bool. Also I'd prefer _set to _setter.

It's not a big thing, but it means filenames that are more human-legible, if
a little less machine-readable.

Cheers,
Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top