eo icon indicating copy to clipboard operation
eo copied to clipboard

implement `seq` in EO with the help of `dataized`

Open yegor256 opened this issue 10 months ago • 5 comments

I believe, it should be possible, with the help of recursion

yegor256 avatar Apr 10 '24 15:04 yegor256

I think we will need try object here because it has finally attribute which just dataizes object and forgets about it

maxonfjvipon avatar Apr 10 '24 20:04 maxonfjvipon

@yegor256 @maxonfjvipon @volodya-lombrozo is this issue free? can I take this one?

l3r8yJ avatar Apr 13 '24 10:04 l3r8yJ

@l3r8yJ thanks for your desire to help. Of course you can try, but it would be kind of dirty implementation which abuses the design of try. So I'm not sure we really need it now in such way. @yegor256 WDYT?

maxonfjvipon avatar Apr 13 '24 11:04 maxonfjvipon

@maxonfjvipon then maybe you know an another issue I can help with?

l3r8yJ avatar Apr 13 '24 12:04 l3r8yJ

@maxonfjvipon I would wait a bit with this ticket

yegor256 avatar Apr 13 '24 15:04 yegor256

[steps] > seq
  loop 0 > @

  [index] > loop
    if. > @
      and.
        index.lt steps.length
        (dataized (steps.at index)).size.ge 0 # any convertion to true
      loop (index.plus 1)
      true

Variants of convertion to true

  1. (dataized (steps.at index)).size.ge 0
  2. (dataized (steps.at index)).as-bool.if true true

Chamber6821 avatar Jun 09 '24 14:06 Chamber6821

To deny remove dataization object must have flag that dataization of object has side effects. I think about this mechanism as portal from declarative EO to platform, for example any call of C API has side effect

Chamber6821 avatar Jun 09 '24 14:06 Chamber6821

It is works!

# The test Application with very important comment XXXXXXXXXXXXXXXXXX.
[args] > app
  my-seq > @
    *
      QQ.io.stdout "1\n"
      QQ.io.stdout "2\n"
      QQ.io.stdout "3\n"
      QQ.io.stdout "4\n"

  [steps] > my-seq
    loop 0 > @

    [index] > loop
      if. > @
        and.
          index.lt steps.length
          steps.at index
        ^.loop
          index.plus 1
        true

Chamber6821 avatar Jun 09 '24 15:06 Chamber6821

@Chamber6821 looks pretty good. But the logic of seq assumes that it dataizes all the steps except the last one, which is just returned without dataization. You may see it here (ind < items.length - 1)

maxonfjvipon avatar Jun 09 '24 16:06 maxonfjvipon

@maxonfjvipon fixed

# The test Application with very important comment XXXXXXXXXXXXXXXXXX.
[args] > app
  my-seq > @
    *
      QQ.io.stdout "1\n"
      false
      QQ.io.stdout "2\n"
      false
      QQ.io.stdout "3\n"
      false
      QQ.io.stdout "4\n"
      false

  [steps] > my-seq
    loop 0 > @

    [index] > loop
      if. > @
        and.
          index.lt (steps.length.minus 1)
          or.
            (dataized (steps.at index)).as-bool
            true
        ^.loop
          index.plus 1
        steps.at index

Chamber6821 avatar Jun 09 '24 17:06 Chamber6821

@Chamber6821 much better, one more thing: if steps is empty - seq should return true

maxonfjvipon avatar Jun 09 '24 17:06 maxonfjvipon

@maxonfjvipon

# The test Application with very important comment XXXXXXXXXXXXXXXXXX.
[args] > app
  my-seq > @
    *
      QQ.io.stdout "1\n"
      false
      QQ.io.stdout "2\n"
      false
      QQ.io.stdout "3\n"
      false
      QQ.io.stdout "4\n"
      false

  [steps] > my-seq
    if. > @
      steps.length.eq 0
      true
      loop 0

    [index] > loop
      if. > @
        and.
          index.lt (steps.length.minus 1)
          or.
            (dataized (steps.at index)).as-bool
            true
        ^.loop
          index.plus 1
        steps.at index

Chamber6821 avatar Jun 09 '24 17:06 Chamber6821

I will create PR

Chamber6821 avatar Jun 09 '24 18:06 Chamber6821

@Chamber6821 yeah, you can try

maxonfjvipon avatar Jun 09 '24 18:06 maxonfjvipon

@yegor256 let's make a new release with tag 0.38.4

maxonfjvipon avatar Jun 13 '24 15:06 maxonfjvipon

@rultor release, tag is 0.38.4

yegor256 avatar Jun 13 '24 16:06 yegor256

@rultor release, tag is 0.38.4

@yegor256 OK, I will release it now. Please check the progress here

rultor avatar Jun 13 '24 16:06 rultor

@rultor release, tag is 0.38.4

@yegor256 Done! FYI, the full log is here (took me 15min)

rultor avatar Jun 13 '24 16:06 rultor

@yegor256 I'm closing it since it's implemented

maxonfjvipon avatar Jun 28 '24 07:06 maxonfjvipon