Coder Social home page Coder Social logo

Comments (17)

dylanbeattie avatar dylanbeattie commented on July 17, 2024 2

The point about mysterious proxying EOF is a very, very good one - it makes absolutely sense that you should be able to iterate across an array (or read from STDIN in a loop) and read empty strings, falses and zeros but still stop when you reach the end of the collection.

I'm starting to pull together issues for the next iteration of Rockstar, and this one is definitely one to include.

from rockstar.

gaborsch avatar gaborsch commented on July 17, 2024 1

Here's a possible solution for this issue:

  • iterate thru the space-split segments
  • split all segments into character arrays
  • check the length of the character arrays, if it's greater than 0, then it's valid
X is " 0     23 "
split X with " "

Let i be 0
while i is less than X
  let Y be X at i
  build i up
  split Y into Z
  say "Y=" + Y + ", Z=" + Z
  if Z is greater than 0
    say "valid"
    cast Y
    (Y is numeric now)
'''

from rockstar.

caseyc37 avatar caseyc37 commented on July 17, 2024 1

Here's another possible solution: use the "with" keyword. Twice.

(Input contains the value to be tested)
Let Test be Input with 1
Let Test be Test with 1

After those lines, different values of Input will result in different values of Test:

Input Test
"" "11"
"0" "011"
0 2
mysterious "mysterious11"

...at which point it's fairly trivial to tell them apart by looking at the value of 'test'.

from rockstar.

gaborsch avatar gaborsch commented on July 17, 2024 1

@weshinsley True - and also, it makes mysterious meaningless (if you follow me :) ). So it would be a useless feature - but why should we keep it?

Dylan once said he is not afraid of breaking changes - and we can provide a proper compiler for each version (once there's a breaking change, I will save a version of Rocky to support the old version).

So, old codes will be able to run on old versions. We only need to distinguish them.

from rockstar.

weshinsley avatar weshinsley commented on July 17, 2024

OK - I think I can skirt around the comparison issues (for now) with

listen to input
split input into pieces with "  "
join pieces into newinput with " "
split newinput into newpieces with " "

but I might run into problems comparing the 0 with things later...

from rockstar.

weshinsley avatar weshinsley commented on July 17, 2024

And

 6  3 47 94  2

with a leading space is tricky (although we know in this case the leading space is not a zero...)

from rockstar.

weshinsley avatar weshinsley commented on July 17, 2024

That's clever - I wouldn't have thought of the split Y into Z line...

from rockstar.

weshinsley avatar weshinsley commented on July 17, 2024

So... the crux of the matter for me is this... suppose you have 3 lines of input that goes:-

123
0
234

If you've coded in other languages, you might expect mysterious to be a kind of proxy for eof - like:

listen to my heart
while my heart isn't mysterious
  whisper my heart
  listen to my heart

which stops reading early, because the character/string "0" turns out to be mysterious. It's a bit of a surprise, since "0" is not something I think most coders would class as "undefined". (It has length after all...) I think the simplest working form might be:-

listen to my heart
split my heart into my pancreas
while my pancreas isn't mysterious
  unite my pancreas into my spleen
  shout my spleen
  listen to my heart
  split my heart into my pancreas

Or, to put it another way, is mysterious isn't always the most practical way of determining mysterious-ness, when there are zeroes floating about. Instead, we want to...

mysteriousness takes victim
  shatter victim into particles
  if particles greater than 0
    (victim isn't mysterious)


But this all feels a little bit clumsy, and I wonder if mysterious slightly overplays its hand here?

from rockstar.

weshinsley avatar weshinsley commented on July 17, 2024

Great :-)

Related: To solve the AoC puzzle, I flattened my 5x5 grid of numbers into an array of 25 numbers, indexes 0..24 inclusive. I then wanted to have a lookup table - a sparse associative array that lets me ask: where (if at all) does this number occur in this array. The intention is that numbers not present return "mysterious", as no entry is found in my lookup.

So unless I work around it, I have a problem distinguishing between "mysterious" meaning undefined (the number is not in my 0..24 array at all), or that it is present at position zero.

As a suggestion on how it could improve in a reasonably backward-compatible way - what about an additional term "meaningless", meaning something that really is a null/undefined. Brief (but very deep) poetic support for this suggestion:-

Everything that's meaningless is mysterious
But not everything mysterious is meaningless

from rockstar.

caseyc37 avatar caseyc37 commented on July 17, 2024

One simple workaround is to have your array return 1-25 for items in your array (subtract 1 to get the actual position) and mysterious for anything not in the array.

from rockstar.

weshinsley avatar weshinsley commented on July 17, 2024

Yeah, and that's what I do, and the occasional build up and knock down doesn't hurt. There may be other times though where you'd want to distinguish between zero and missing more immediately.

from rockstar.

gaborsch avatar gaborsch commented on July 17, 2024

Actually, it's rather a bug. The Spec says:

<Mysterious> <op> Mysterious => Equal.
<Non-Mysterious> <op> Mysterious => Non equal.

0 is non-mysteriuos, so 0 must not be equal to mysterious.

Also, the tests do not comply with this rule (equality/mysterious.rock): mysterious is null is expected to have true as a result (there is no test with 0 comparison)

from rockstar.

weshinsley avatar weshinsley commented on July 17, 2024

All of these succeed at present (on the TRY IT page) :-

if "0" is mysterious
  shout "0 in quotes is mysterious"

if 0 is mysterious
  shout "0 without quotes is mysterious"

if "" is mysterious
  shout "empty string is mysterious"

if empty is mysterious
  shout "empty is mysterious"

if " " is mysterious
  shout "space is mysterious"
  

from rockstar.

weshinsley avatar weshinsley commented on July 17, 2024

This also succeeds:-

if mysterious is mysterious
  shout "mysterious is mysterious"

but this (which is genuinely undefined) locks up - that's probably a different issue.

if potato is mysterious
  shout "where did that potato come from"

from rockstar.

gaborsch avatar gaborsch commented on July 17, 2024

@dylanbeattie To incorporate the EOF-as-mysterous feature, we need to clear the mystery around mysterious. It makes no sense for this feature if we cannot decide whether it's EOF, or we read empty line, 0, "0" or " " for the input.

It will cause a breaking change, though. Maybe worth to think on versioning as well.

from rockstar.

weshinsley avatar weshinsley commented on July 17, 2024

My thought was that an additional meaningless might allow mysterious to stay as it is, avoiding any breakage... ALTHOUGH I suppose that will affect those who already have meaningless in their lyrics, so... hmm...!

from rockstar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.