<davexunit>anyone familiar with vector math? I have a 2D vector type, and now I'm adding a 3D vector type. Ideally, I'd like to use the same procedures to operate on both types of vectors and DTRT. <davexunit>and I have to handle cases like adding a 2d vector to a 3d vector. <davexunit>should [1 1] + [1 1 1] = [2 2 1] or throw an error? <davexunit>it would be convenient to treat 2d vectors as 3d vectors with a 0 z component, but I don't think it's necessarily the right way to do things. <davexunit>I guess throwing an error would be best, for mathematical correctness. ***fangism is now known as fangism-ctrl-Z
***sethalve_ is now known as sethalves
<b4283>are the forms (define (a x) x) and (define b (lambda (x) x)) equivalent ? <b4283>nvm, i've found the answer R6RS:11.2.1 Variable definitions <b4283>i wonder why The Little Schemer prefer the latter form <nalaginrut>I picked the former now, because wingo told me do so <b4283>nalaginrut: the lambda is just redundant, but if the scheme language want to trim down the fats, the latter form would probably go <b4283>but i think (define (a x) x) has the disadvantage to make people misunderstand that there's a function namespace ***linas__ is now known as linas
<jmd>bhattigurjot: And what are you trying to do? <jmd>Then you need the -dev package. <bhattigurjot>jmd: but this -dev package must be 2.0.11 compatible.. right? <jmd>apt-get install guile-dev <jmd>Obviously if you are using unstable, you are expected to know what you are doing. <lloda>davexunit: [a b] + [c d e], I think it should be an error. <lloda>Not because of math correctness, I think that's arbitrary. It may be correct to pad with 0 if you define it so. J pads with 0. In an OpenGL context it makes sense to have [a b] = [a b 0] (or [a b] = [a b 0 1] I suppose). <lloda>But because it's easier to be strict and then relax, than the other way around, if you change your mind. <saul>b4283, defining with lambda is useful when creating generators or otherwise capturing state. For example, (define gen-counter (let ((count 0)) (lambda () (set! count (+ count 1)) count))) <davexunit>lloda: I came to same conclusion that [a b] + [c d e] should be an error. now I have a new problem! <lloda>davexunit: which problem? btw the Guile routines (vector-map, array-map!, etc) accept mismatched sizes, so you'd need to wrap them (or not use them) if you don't want to <lucasaiu>I have a nice idea for a GHM presentation <lucasaiu>Un nouveau port d'epsilon, sur une machine très petite <lucasaiu>The title will be "ode to a childhood dream" <davexunit>lloda: ah, sorry. I'm not representing vectors (math) as vectors (data structure) <lucasaiu>An epsilon cross-compiler for the Commodore 64 <civodul>you'll have to bring a Commodore 64, then <davexunit>lloda: my new problem is that I want my vector procedures to support 2D and 3D vectors. I have a procedure for adding vectors, v+, and it accepts 0 or more vectors. By supporting multiple types of vectors, the case where 0 vectors are given is undefined. <davexunit>adding 0 vectors should result in the null vector, but there's no way to determine the dimensionality of that vector. <lloda>davexunit: You could support frame-matching :) then you could just return 0 there. <lloda>the frame is the shape of the array. For a 3D vector, that's [3]. For a 3D vector, that's [2]. For a scalar, that's []. <lloda>(for a 3x3 matrix, it would be [3 3]). <lloda>two operands are compatible if their frames 'match' <lloda>which means that they have the same values in the same places, and you ignore the places without values. <lloda>so [3] matches [3], [3 4], or [3 9 4]. <davexunit>I'm not sure that will help solve my problem. <lloda>it means that you define (+ [a b c] d) as [(+ a d) (+ b d) (+ c d)] ***dsmith-w` is now known as dsmith-work
<lloda>your identity for 3D/2D + is now just 0 <davexunit>I still want 2D/3D vectors to be incompatible for addition and such. <lloda>my experience is that it's much harder to mix ranks by mistake, than it is to mix sizes. <davexunit>another question: I currently have a 2d vector defined as a record type. should I just use the vector data structure? <davexunit>yeah, an array might be better than a vector. <davexunit>it is somewhat convenient to have a distinct data type for the vector, but maybe it's not worth it. <civodul>i mean arrays are meant to be used to represent vectors and matrices of all kinds <civodul>it's a fundamentally imperative data structure though <davexunit>yeah, I made my vector type immutable, which is also useful. <lloda>what does fundamentally imperative mean? you can use arrays functionally <lloda>the immutability bit is going to happen at some point because of the problem with modifying literals <lloda>arrays are useful if you manipulate lots of vectors together, and you take advantage of the generality and the O(1) operations (different ranks, reshaping, transposing). If you manipulate 2/3D vectors individually, there's little difference with using a record. <lloda>that said, having more people using Guile arrays would be good for Guile, I think <civodul>lloda: one can use arrays functionally, but it's going to be terribly inefficient: you'd have to copy the whole array each time you modify a cell <lloda>right, inefficient for large arrays <davexunit>right now, I do 2d vector math by producing a new vector2 object for each operation like addition, scalar multiplication, cross product. <davexunit>which is inefficient, but I think making my vector2 type mutable is asking for trouble. <civodul>davexunit: vector2 means a 2-element vector, right? <lloda>those are very small objects, I doubt it's too inefficient, especially when all the components of the result are new <davexunit>I'm sort-of emulating what I see in other game engines that provide vector2, vector3, and sometimes vector4 types. <davexunit>most importantly, the OpenGL shading language provides these 3 types. <b4283>saul: yeah, i know about closure <davexunit>additionally, I have a 4x4 matrix type, which does use an array. <davexunit>and operations on matrices return new matrices, which is more inefficient because it's 16 elements. <stis>at least that is my dream parser framewark, pretty function oriented <stis>does everything in one pass, scanning parsing and tokenizing <stis>I used it as a test case for the guile-log parser framework ***fangism-ctrl-Z is now known as fangism
<sneek>wingo was here May 12 at 06:35 pm UTC, saying: brb. <sneek>civodul was here May 12 at 02:37 pm UTC, saying: heheh. <civodul>stis: "get sage to run on Guile", oouch! <stis>civodul: not yet, buut most of the spec is translated <stis>remains to debug the tool a little <stis>the sage thing is to have a cool goal. Probably impossible to reach it :-) <civodul>but the parser in that repo is surprisingly small <civodul>i guess guile-log does a lot of the heavy lifting? <stis>Yep, there is a heavy macro, setup-parser, that create a functional parser framework with arbruitrary variables that can flow with the parsing <stis>I needed to mod the vanilla parser to introduce the identation stack <stis>so everything is done in one pass, also the identation handling. <stis>another nice feature is that the tokenizer is done very loose via memoization, this means that the parser is much faster than what you would believe <stis>and of cause you can use backtracking, and all kanrenlike features for parsing such as the interleaving, storage of state and restorage of stete etc <stis>but those features are a bit of overkill <cluck>it would be hilarious if guile managed to hijack python2's community and left python 3 eating dust <stis>cluick: tail calls, continuations ...