These are chat archives for pybee/general

6th
Jan 2017
Kenneth Love
@kennethlove
Jan 06 2017 00:00
you can't trust ascii
or any encoding
Philip James
@phildini
Jan 06 2017 00:00
(fwiw, I don’t think JS even has this concept)
Kenneth Love
@kennethlove
Jan 06 2017 00:00
they're all hiding something
Jacob Stoebel
@jstoebel
Jan 06 2017 00:00
hey thanks!
Philip James
@phildini
Jan 06 2017 00:01
>>> "%#c" % 5
'\x05'
>>> "%#c" % 10000
'✐'
>>> "%#c" % 21
'\x15’
finally!
it’s that middle one I find hilarious.
Jacob Stoebel
@jstoebel
Jan 06 2017 00:02
what is it even?
Philip James
@phildini
Jan 06 2017 00:03
unicode emoji.
this is lending credence to my idea that #c tries to map to ascii encodings in some hilarious way.
Jacob Stoebel
@jstoebel
Jan 06 2017 00:04
the # is insignificant btw i was just the test case I happened to paste in
Philip James
@phildini
Jan 06 2017 00:04
but it’s not insignificant, I argue.
oh weird. ok, maybe it is.
Philip James
@phildini
Jan 06 2017 00:05
'c' Character. Converts the integer to the corresponding unicode character before printing.
Jacob Stoebel
@jstoebel
Jan 06 2017 00:05
ah is that a change from python2?
Philip James
@phildini
Jan 06 2017 00:05
so, yeah. it’s taking an integer as input and trying to map that to a unicode character.
this is in the python 2 docs.
Jacob Stoebel
@jstoebel
Jan 06 2017 00:05
ok i couldn't find that resource for python 3
the doc from python2 is the best i could fine
the ‘c’ character is an “integer presentation type"
>>> "%c" % 65A'
Jacob Stoebel
@jstoebel
Jan 06 2017 00:09
gotcha, so I need the opposite of charCodeAt
Philip James
@phildini
Jan 06 2017 00:09
of course, it’s not even using the Unicode absolute number, it’s using the decimal/HTML number. because of course it is. :face_with_rolling_eyes:
Jacob Stoebel
@jstoebel
Jan 06 2017 00:10
> String.fromCharCode(65)
'A'
Philip James
@phildini
Jan 06 2017 00:10
that’s the JS string, right? trying in node?
Jacob Stoebel
@jstoebel
Jan 06 2017 00:10
yep
Philip James
@phildini
Jan 06 2017 00:11
yeah, seems correct.
Jacob Stoebel
@jstoebel
Jan 06 2017 00:11
but:
> String.fromCharCode(\x05)
String.fromCharCode(\x05)
                    ^
SyntaxError: Invalid or unexpected token
Philip James
@phildini
Jan 06 2017 00:13
so… the tricky thing is anything under 32 is a special character that can’t be printed to screen well.
Jacob Stoebel
@jstoebel
Jan 06 2017 00:13
yes
but I take that back, what I need to do is:
> String.fromCharCode(5)
'\u0005'
Philip James
@phildini
Jan 06 2017 00:13
right.
Jacob Stoebel
@jstoebel
Jan 06 2017 00:13
i need it to return \x05
Philip James
@phildini
Jan 06 2017 00:13
and then translate that into \x05...
this is awful and dangerous: '\u0005'.encode('utf-8’)
and you’ll end up with a python3 byte-string, so I don’t really know what will happen.
Jacob Stoebel
@jstoebel
Jan 06 2017 00:18
that's in node?
Philip James
@phildini
Jan 06 2017 00:18
this might be a case of “make it good enough, leaving comments indicating there are special cases, and then find a better solution when we hit the bug"
no, that’s in python.
Jacob Stoebel
@jstoebel
Jan 06 2017 00:18
ah
Philip James
@phildini
Jan 06 2017 00:19
but if we haven’t figured out the python string-encoding libraries first, that might precede ’%c’
Jacob Stoebel
@jstoebel
Jan 06 2017 00:20
ok well the good news is we can still handle anything >= 32
Philip James
@phildini
Jan 06 2017 00:20
yep, totally. It will Do The Right Thing.
Jacob Stoebel
@jstoebel
Jan 06 2017 00:20
I'll make a special test for this edge case and mark it expected fail
Philip James
@phildini
Jan 06 2017 00:20
excellent idea.
Jacob Stoebel
@jstoebel
Jan 06 2017 00:20
well thanks all the same
Philip James
@phildini
Jan 06 2017 00:21
thank you for working on BeeWare. :)
Russell Keith-Magee
@freakboy3742
Jan 06 2017 00:37
@kennethlove Ok - I’ve fixed it now, and I just ran through the tutorial from scratch to check.
Jacob Stoebel
@jstoebel
Jan 06 2017 01:13
If I want to extract the native JS value of a Batavia Int is there a more elegant way to do so than this?
var Int = require('./batavia/types/Int')
var Float = require('./batavia/types/Float')
var types = require('../types');

var n = new Int(5)
// I want to extract the native JS value of n

if ( types.isinstance(n, [Int, Float]) ){
  var js_value = Number(n.valueOf())

} else {
  js_value = n.valueOf();
}
Jacob Stoebel
@jstoebel
Jan 06 2017 01:30
or would .__repr__() work?
Jacob Stoebel
@jstoebel
Jan 06 2017 01:44

here is the implementation of .valueOf() for Int

Int.prototype.valueOf = function() {
    return this.val.valueOf();
}

Am I wrong or shouldn't this be Number(return this.val.valueOf());?

Jacob Stoebel
@jstoebel
Jan 06 2017 01:51
or just return this.val?
Katie McLaughlin
@glasnt
Jan 06 2017 03:03
Hey, @freakboy3742 is doing a live chat thing right now if anyone is interested: https://www.youtube.com/watch?v=_-_qwJe498c
Russell Keith-Magee
@freakboy3742
Jan 06 2017 04:44
IM IN UR TVS TALKING ABOUT UR BEES
Philip James
@phildini
Jan 06 2017 04:47
truth.
Russell Keith-Magee
@freakboy3742
Jan 06 2017 04:48
I HEARD YOU LIKE BEES SO I PUT BEES ON YOUR PYTHON
Sanjeev
@Sanjeev-S
Jan 06 2017 05:10
^_^
Sanjeev
@Sanjeev-S
Jan 06 2017 12:30
I made a new PR.(pybee/voc#339) Just a trivial one to see if I got it all figured out on my own. But I just noticed that it is already done. ( pybee/voc#313 ). And that was more than a month ago. But it has not yet been merged. Is there anything else to be done? Or should I just close my pull request? (Anyway it served it's purpose to me for learning :) )
Vojtěch Jelínek
@vojtechjelinek
Jan 06 2017 17:11
@jstoebel Use .int32() or .bigNumber() depends on what you want. Int uses BigNumber library.
Jacob Stoebel
@jstoebel
Jan 06 2017 17:14
gotcha so just to make sure I understand, to get the native JS number from a Batavia int I would do something like:
var i = new Int(5);
console.log(i.int32());
Vojtěch Jelínek
@vojtechjelinek
Jan 06 2017 17:16
Yes, but if you need to work with numbers bigger than 9223372036854775807 you need to use the BigNumber library and .bigNumber() method.
Jacob Stoebel
@jstoebel
Jan 06 2017 17:16
thanks
and how would I do that? The following doesn't work
var i = new Int(new BigNumber(9223372036854775808));
/Users/stoebelj/batavia/node_modules/bignumber.js/bignumber.js:1213
            throw error;
            ^

BigNumber Error: new BigNumber() number type has more than 15 significant digits: 9223372036854776000
    at raise (/Users/stoebelj/batavia/node_modules/bignumber.js/bignumber.js:1181:25)
    at new BigNumber (/Users/stoebelj/batavia/node_modules/bignumber.js/bignumber.js:264:21)
    at Object.<anonymous> (/Users/stoebelj/batavia/scratch.js:50:17)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:420:7)
never mind, it needs to be a string. spoke too soon
var i = new Int(new BigNumber("9223372036854775808"));
console.log(i.bigNumber());
{ [String: '9223372036854775808'] s: 1, e: 18, c: [ 92233, 72036854775808 ] }
Vojtěch Jelínek
@vojtechjelinek
Jan 06 2017 17:23
var i = new Int("9223372036854775808"); is enought
Jacob Stoebel
@jstoebel
Jan 06 2017 17:23
you're right!
thanks for the help
Jacob Stoebel
@jstoebel
Jan 06 2017 17:30
the problem I'm up against is that I need to extract the native value from a Batavia type but it could be a a String, Float or Int. Does this mean I need to check the batavia type then run the appropriate method like so?
      function getJSValue(bataviaType){
        // bataviaType: a batavia type, must be int, float or str
        // returns the underlying JS type.

        if ( types.isinstance(bataviaType, types.Int) ){
          return bataviaType.bigNumber().valueOf();
        } else {
          return bataviaType.valueOf();
        }
      }
Vojtěch Jelínek
@vojtechjelinek
Jan 06 2017 17:47
Yes, but the return statement should be return Number(bataviaType.toString()) and you will lost some precision.
Jacob Stoebel
@jstoebel
Jan 06 2017 20:05
@Slepice1 thanks for your help!