Giter VIP home page Giter VIP logo

Comments (6)

jnthn avatar jnthn commented on June 18, 2024 3

What @AlexDaniel said: we should start with the problem. I speculate the problem is:

  • It's tiresome to write my Buf $x .= new; $x.write-int32(42); to get a Buf containing the encoding of that integer value
  • There's no ideal way to get a Blob rather than a Buf if wanting to have it as an immutable value

Those are probably fair problems, thought the solution proposed here doesn't seem ideal to me, since:

  • Things like Str are also Cool, and having that be numified in response to .Buf or .Blob feels a bit odd. Folks would quite possibly expect it to do something like .encode does.
  • There is no "correct size" for the integer 1. Depending on the needs of the binary format being produced, it could be represented in 1 byte, 2 bytes, 4 bytes, or 8 bytes.

I'd be more in favor of factory methods on Blob/Buf, so you could do Blob.from-int32(-1) and it'd produce a 4-byte Blob holding the representation of -1; endianness can optionally be provided as it is in write-int32.

from problem-solving.

CurtTilmes avatar CurtTilmes commented on June 18, 2024 1

While you're at it, how about taking an array (Iterable) as input as well?

from problem-solving.

AlexDaniel avatar AlexDaniel commented on June 18, 2024

OK, but which problem is this going to resolve?

Edit: Maybe it should be stressed in the README that the ticket should clearly explain what the problem is, before proposing a solution. We had a similar issue before: https://colabti.org/irclogger/irclogger_log/perl6?date=2019-04-05#l523

from problem-solving.

lizmat avatar lizmat commented on June 18, 2024

That'd work for me too :-)

from problem-solving.

jnthn avatar jnthn commented on June 18, 2024

@CurtTilmes Perhaps, but we have to be a bit careful, in that arrays in numeric contexts typically numify. It'd not be unreasonable for somebody to write my $chunk-count = Blob.from-int32(@chunks) and expect to have a Blob with the number of elements in the array encoded. It's a natural generalization for anyone happily doing if @stuff == 1 { } and similar.

Maybe a plural version of the methods: Blob.from-int32s(@values)?

from problem-solving.

CurtTilmes avatar CurtTilmes commented on June 18, 2024

Sounds good. I like this because it makes a few things easier.

Native types, shaped arrays, Blob-ifying numbers, etc. are on their way to competing with NumPy and PDL, but I still don't understand how it all fits together.

I like Blobs because they are easy to work with for NativeCall, but it seems that instead of converting from Int to Blob, I should be using an int32 that really already has the right representation under the sheets, right?

I shouldn't need to convert an array of int32 into a Blob, I should just be able to use an array of int32 directly? Like if a library wants a huge array of int32 as a pointer and a size, what's the efficient way to send it there? I use Blobs and CArrays a lot, but it seems like I am doing extra work.

from problem-solving.

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.