[#3741] Re: Why it's quiet -- standard distribution issues — Aleksi Niemel<aleksi.niemela@...>
I think it's the feature of the mailing list archive to create a threads of
[#3756] RE: XMP on comments — Aleksi Niemel<aleksi.niemela@...>
> require "xmp"
[#3766] modulo and remainder — Dave Thomas <Dave@...>
[#3776] Kernel.rand — Aleksi Niemel<aleksi.niemela@...>
How about defining:
[#3781] Widening out discussions — Dave Thomas <Dave@...>
[#3795] Re: Array.uniq! returning nil — Aleksi Niemel<aleksi.niemela@...>
> As matz said in [ruby-talk:3785] and Dave said in [ruby-talk:1229],
Hi, Aleksi,
[#3823] Re: Array.pick — Aleksi Niemel<aleksi.niemela@...>
> > Just a general comment--a brief statement of purpose and using
[#3827] JRuby? — Aleksi Niemel<aleksi.niemela@...>
Is there or will there be Ruby equivalent of JPython?
[#3882] Re: Array.uniq! returning nil — Aleksi Niemel<aleksi.niemela@...>
> |look too strange, confusing, or cryptic. Maybe just @, $, %, &.
Hi,
[#3918] A question about variable names... — Dave Thomas <Dave@...>
[#3935] If your company uses Pallets, Skids, Boxes, Lumber, etc. — pallets2@...
[#3956] Tk PhotoImage options — andy@... (Andrew Hunt)
Hi all,
[#3971] Thread and File do not work together — "Michael Neumann" <neumann@...>
following example do not work correctly with my ruby
[#3986] Re: Principle of least effort -- another Ruby virtue. — Andrew Hunt <andy@...>
> Principle of Least Effort.
Hi,
[#4005] Re: Pluggable functions and blocks — Aleksi Niemel<aleksi.niemela@...>
Aleksi makes a question:
[#4008] Ruby installation instructions for Windows — Aleksi Niemel<aleksi.niemela@...>
I had to write these instructions for my friends. I thought it might be nice
[#4043] What are you using Ruby for? — Dave Thomas <Dave@...>
On 15 Jul 2000 22:08:50 -0500,
Hi,
[#4057] Re: What are you using Ruby for? — Aleksi Niemel<aleksi.niemela@...>
Johann:
[#4082] Re: What are you using Ruby for? — Aleksi Niemel<aleksi.niemela@...>
[#4091] 'each' and 'in' — hal9000@...
I just recently realized why the default
[#4107] Re: 'each' and 'in' -- special char problem? — schneik@...
[#4114] Method signature - a question for the group — Dave Thomas <Dave@...>
[#4139] Facilitating Ruby self-propagation with the rig-it autopolymorph application. — Conrad Schneiker <schneik@...>
Hi,
[#4158] Getting Tk to work on Windows — "Michael Neumann" <neumann@...>
Hi....
[#4178] Partly converted English Ruby/Tk widget demo working. — Conrad Schneiker <schneik@...>
Hi,
[#4234] @ variables not updated within method? — Hugh Sasse Staff Elec Eng <hgs@...>
Hugh Sasse Staff Elec Eng <hgs@dmu.ac.uk> writes:
On 27 Jul 2000, Dave Thomas wrote:
[#4267] Ruby.next, Perl6, Python 3000, Tcl++, etc. -- Any opportunities for common implementation code? — "Conrad Schneiker" <schneiker@...>
Hi,
"Conrad Schneiker" wrote:
[ruby-talk:03755] XMP on comments
require "xmp"
xmp <<-EOS
xmp = "can't handle comments"
a = [1,2,3]
# in block it tries to evaluate
# anyway it's quite a hack,
# there's no hope I'm going to fix it,
# I decided after 5 minutes of pure amaze :)
EOS
produces:
./xmp.rb:182:in `eval': (eval):40: compile error (SyntaxError)
(eval):16: parse error
^/, ___sep___);
^
(eval):21: unmatched ): /, ___sep___);
rescue
___res___ << "!! " + $!;
end
begin
___res___ << "=> " + ().inspect.gsub(/
(eval):27: unmatched ): /, ___sep___);
rescue
___res___ << "!! " + $!;
end
begin
___res___ << "=> " + (# anyway it's quite a
hack,).inspect.gsub(/
(eval):33: unmatched ): /, ___sep___);
rescue
___res___ << "!! " + $!;
end
begin
___res___ << "=> " + (# there's no hope I'm going to fix it,
).inspect.gsub(/
(eval):39: unmatched ): /, ___sep___);
rescue
___res___ << "!! " + $!;
end
begin
___res___ << "=> " + (# I decided after 5 minutes of pure
amaze :)).inspect.gsub(/
(eval):40: unterminated regexp meets end of file
from ./xmp.rb:182:in `xmp'
from ../xmp_hacked/xmptest.rb:2
################################################
The I relooked it and decided to give a try. I managed to "fix" the
functionality (probably introducing an error since it prints out even things
evaluating to nil). Then I patched the documentation (my English is bad too
!) and finally added one small functionality so that one can say 'ruby
xmp.rb test.rb' and xmp prints the code in test.rb.
The patch is here, apply the parts you see worthwhile.
- Aleksi
#################################################
--- ../xmp/xmp.rb Mon Feb 7 07:54:02 2000
+++ xmp.rb Mon Jul 3 02:32:30 2000
@@ -12,24 +12,30 @@
== DESCRIPTION
-((*xmp*)) is an example printer, which is helpful to show example
-code. The function (({xmp})) evaluates the first argument
-((|string|)) then prints the ((|string|)) result value. If
+((*xmp*)) is an example printer. It makes it easier to write example
+code. It executes given code line by line printing the code and
+evaluated result.
+
+The function (({xmp})) evaluates the first argument ((|string|))
+(code) and then prints the code and evaluated value ((|string|))
+result value.
+
+The second argument ((|fmt|)) specifies the report format. The format
+string ((|fmt|)) can include special patterns "%l" and "%r". "%l"s
+are replaced with the code line and "%r" with the result. If
(({false})) or (({nil})) is given as second argument ((|fmt|)),
(({xmp})) doesn't print the result.
-The second argument ((|fmt|)) specifies the report format. In format
-string ((|fmt|)), special patterns "%l" and "%r" are available. "%l"s
-are replaced by the line and "%r" by the result.
-
The third argument ((|sep|)) specifies the report separator for the
multi-line output. This string ((|sep|)) is put between the output
lines unless ((|fmt|)) is false.
Unless (({false})) is given as the second argument, (({xmp})) can't
-treat a statement which consist of more than one line.
+treat a statement which consist of more than one line. If (({false}))
+is given as the second argument (({xmp})) doesn't print the evaluated
+result. In other words it doesn't support multi-line statements.
-== CONSTANT
+== CONSTANTS
:XMP_VERSION
(({XMP_VERSION})) is version string which stand for the last modification
@@ -54,7 +60,7 @@
=== EXAMPLE 2
-To show each lines
+To demonstate few built-in library functions
xmp <<-EOS
a = "The moon Fly"
@@ -114,13 +120,14 @@
== TIPS
-(({xmp})) puts ``(({#=> }))'' to each values. It is covenient when one
-includes (({xmp}))'s output to an email message by directly cut & paste
-because such message can be cut & paste again to execute by a reader.
-
-Combinating with (({if __FILE__ == $0})) technic, (({xmp})) is useful to
-show how to use user's library. For example, one can put some code at
-the end of foo.rb to show usage as follows:
+By default (({xmp})) prepends ``(({#=> }))'' to each evaluated result.
+It is convenient when one includes (({xmp}))'s output to an email
+message by cutting & pasting because such messages can be cut & pasted
+immediately to ruby interpreter by recipient.
+
+In combination with (({if __FILE__ == $0})) idiom, one can give an
+example how to use the functionality in the source file. For example,
+one can put some code at the end of foo.rb to show usage as follows:
if __FILE__ == $0
require "xmp"
@@ -138,6 +145,10 @@
EOS
end
+Another example in the end of (({xmp.rb})). For code demonstrating
+purposes, however, usage of RubyUnit or Testsupp might be more
+appropriate.
+
== SEE ALSO
Irb - interactive ruby (written by Keiju Ishitsuka)
@@ -147,10 +158,13 @@
(({Xmp}))'s report follows the outout of the first argument ((|string|)) to
the standard output or the standard error.
+Doesn't handle multi-line statements or comments (well at least :).
+
== HISTORY
- 07 Feb 00: format customizing and excepcion reporting
(gotoken@notwork.org)
- 03 Jan 00: documentation (gotoken@notwork.org)
+2000-07-03: few changes in documentation and simple comment handling
(aleksi)
+2000-02-07: format customizing and excepcion reporting
(gotoken@notwork.org)
+2000-01-03: documentation (gotoken@notwork.org)
== URL
@@ -164,8 +178,8 @@
=end
module Kernel
- XMP_VERSION = "2000-02-07"
- XMP_DEFAULT_OPTION = ["%l\n #%r\n", "\n # "]
+ XMP_VERSION = "2000-07-03"
+ XMP_DEFAULT_OPTION = ["%l\n #=> %r\n", "\n # "]
def xmpsec(*a) puts *a; end
@@ -176,7 +190,7 @@
eval(arg.gsub(/^(.*)\n?/){
%Q|
begin
- ___res___ << "=> " + (#{$1}).inspect.gsub(/\n^/, ___sep___);
+ ___res___ << eval(%Q{$1}ァ).inspect.gsub(/^\n/, ___sep___);
rescue
___res___ << "!! " + $!;
end|}, TOPLEVEL_BINDING)
@@ -194,6 +208,10 @@
end
if __FILE__ == $0
+ if ARGV[0] then
+ xmp open(ARGV[0]).read
+ exit
+ end
puts "## EXAMPLE 1"
xmp "nil.to_i"