Arc Forumnew | comments | leaders | submitlogin
1 point by akkartik 4930 days ago | link | parent

I'm talking about inside the print method you mentioned. Say I want to print the length of the table inside print(), how would I get that?


1 point by rocketnia 4930 days ago | link

I assume Pauan meant you'd change this...

  (object print (fn () "%custom printing!%"))
...to something like this:

  (letr self (object)
    (set-attribute self 'print
      (fn () (+ "#<table of length " len.self ">"))))
At least in the short term, 'til there's some kind of 'w/object to help out. ^_^

-----

1 point by Pauan 4929 days ago | link

No no no. I mean, yes, your way will work, but you can just use letr. No need to use set-attribute:

  (letr self (object print (fn () (+ "#<table of length " len.self ">")))
    self)
You can use set-attribute if you want to, but there's no need, since letr behaves like Scheme's letrec.

And soon I'll try changing it so you don't even need the letr:

  (object print (fn () (+ "#<table of length " len.self ">")))

-----

2 points by rocketnia 4929 days ago | link

Ohh, okay! Sorry, for some reason I thought 'letr was another name for 'ret or something. For some reason 'letrec didn't cross my mind. XD

In this kind of situation I use a utility I call 'named:

  (named foo bar)
  -->
  (ret foo nil (= foo bar))

-----

1 point by akkartik 4930 days ago | link

Ah!

What was that word I used to tactfully criticize your writing those many months ago? Well, Pauan is making you look good >;)

Another way to say that: you've taken the trouble to cater to my idiosyncratic dyslexias. Many thanks!

-----