Skip to content

Commit 9564ed6

Browse files
committed
wrap nqp::sprintf - demo rubyish slurpy args
1 parent 22f47f8 commit 9564ed6

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

examples/rubyish/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,11 @@ curlies `puts fruit{'bananas'}`
5656

5757
nqp op-codes can be called like regular functions. E.g.
5858
```
59-
puts nqp::sprintf("pid=%s time=%d", [nqp::getpid, nqp::time_i])'
6059
puts nqp::if(2+2 == 4, 'yup', 'nope' )
60+
def sprintf(fmt, *args) ; nqp::sprintf(fmt, args) ; end
61+
puts sprintf("pid=%s time=%d", nqp::getpid, nqp::time_i)
6162
```
62-
- this includes nqp control-flow functions:
63+
this includes nqp control-flow functions:
6364
```
6465
n = 99
6566
nqp::while n > 0, begin

examples/rubyish/examples-rubyish/pi.rbi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
LIMIT = 50000
44
def time() ; nqp::time_n() ; end
5+
def sprintf(fmt, *args) ; nqp::sprintf(fmt, args) ; end
56

67
pi_over_4 = 0.0
78

@@ -17,8 +18,8 @@ while n > 0 do
1718
n -= 1
1819
end
1920

20-
puts nqp::sprintf("(completed %d iterations in %.2f sec)",
21-
[LIMIT, time() - start_time])
21+
puts sprintf("(completed %d iterations in %.2f sec)",
22+
LIMIT, time() - start_time)
2223

2324
pi = pi_over_4 * 4
2425
puts pi

0 commit comments

Comments
 (0)