Closed mattnewport closed 2 years ago
I agree. In fact, I think +roll and +reel should be modified to require the initial value as an explicit argument.
On Wed, Aug 28, 2019 at 6:42 PM Matt Newport notifications@github.com wrote:
The left and right fold functions roll and reel use the bunt value for their accumulator. For some functions like product rather than sum it would be useful to have variants that take an initial value (1 rather than 0) for the accumulator. This is common in other languages but I don't see a way to do this with the current Hoon standard library.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/urbit/urbit/issues/1679?email_source=notifications&email_token=AAGVR5JQNHJUA22L3SNRWA3QG4SPDA5CNFSM4IR2HER2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HICJKSA, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGVR5OI4PCNVMFL2EJI7ULQG4SPDANCNFSM4IR2HERQ .
--
— ~rovnys-ricfer https://urbit.org
++fold perhaps?
On Wed, Aug 28, 2019 at 18:47, Ted Blackman notifications@github.com wrote:
I agree. In fact, I think +roll and +reel should be modified to require the initial value as an explicit argument.
On Wed, Aug 28, 2019 at 6:42 PM Matt Newport notifications@github.com wrote:
The left and right fold functions roll and reel use the bunt value for their accumulator. For some functions like product rather than sum it would be useful to have variants that take an initial value (1 rather than 0) for the accumulator. This is common in other languages but I don't see a way to do this with the current Hoon standard library.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub < https://github.com/urbit/urbit/issues/1679?email_source=notifications&email_token=AAGVR5JQNHJUA22L3SNRWA3QG4SPDA5CNFSM4IR2HER2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HICJKSA , or mute the thread < https://github.com/notifications/unsubscribe-auth/AAGVR5OI4PCNVMFL2EJI7ULQG4SPDANCNFSM4IR2HERQ
.
--
— ~rovnys-ricfer https://urbit.org
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/urbit/urbit/issues/1679?email_source=notifications&email_token=AAOFPBTZR3CDZP7QQGSKUWDQG4TEFA5CNFSM4IR2HER2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5M634Y#issuecomment-525987315, or mute the thread https://github.com/notifications/unsubscribe-auth/AAOFPBWE5273YBPN5BAF4QLQG4TEFANCNFSM4IR2HERQ .
It's only slightly more awkward to use a mold to set the initial value, this is what _
(ie, $_
) is for:
> (roll "abcdefg" |=([item=@ accumulator=@] (mul item accumulator)))
0
> (roll "abcdefg" |=([item=@ accumulator=_1] (mul item accumulator)))
99.860.048.996.400
But, in fact, +mul
already has the correct initial arguments:
> (roll "abcdefg" mul)
99.860.048.996.400
It's defined as follows:
++ mul
|: [a=`@`1 b=`@`1]
^- @
=+ c=0
|-
?: =(0 a) c
$(a (dec a), c (add b c))
|:(a b)
is morally equivalent to |=(_a b)
(ignoring some effectively irrelevant intermediate de-sugaring).
I'm not sure if it's better to have an explicit argument -- +spin
and +spun
are an interesting example in this regard.
@joemfb I didn't know you could do this (still pretty new to Hoon) but I agree that seems like a reasonable workaround. I'd guess I'm not the only Hoon noob that this would not be obvious to though so an example of this in the docs for roll
and reel
might be helpful.
I agree, this traversals are a good place to talk about bunts and default samples.
/cc @baudtack @rmariani
I modified some Ames code to use +roll or +reel instead of explicit loops. They're growing on me. I think the last time I'd tried them was before the bunting system got redone, and there was some bug that made it hard to get right. They feel better now, and they don't seem as abstruse.
It's still a bit tricky for beginners to use. You have to know a fair amount about how Hoon works to assemble a call. It might actually be good practice for Hoon 201 students.
examples of specifying initial values using |:
have been added to the docs for these two functions
The left and right fold functions
roll
andreel
use the bunt value for their accumulator. For some functions like product rather than sum it would be useful to have variants that take an initial value (1 rather than 0) for the accumulator. This is common in other languages but I don't see a way to do this with the current Hoon standard library.