WTF And?


  • Tutorialist

    work I'm working on a code and I have logic of this number must be <=5 & >=0. When I test this out via thinking and(lte(5, 0), gte(0, 0)) it works fine, but in the code it returns false, so it fails.

    &c.+prefs/set prco=$+prefs/set *=*:@pemit %#=[setq(p, pmatch(%#))]
    			[if(u(fn.iscat?, %0),
    				[if(and(lte(5, %1), gte(0, %1)),
    					[alert(+Prefs)] Setting %0 to %1.
    					[set(%qp, 
    						_prefs.ratings:[get(%qp/_prefs.ratings)].%0:%1
    					)],
    					[alert(+Prefs, alert)] You tried to set '%1'.  You must set a rating of 0 to 5.
    				)],
    				[alert(+Prefs, alert)] I'm sorry but '%0' is not a category.  Check +prefs/list for available categories.
    				)]
    

    in fact this is what is happening in the guts:

    +Prefs Code Object <PrCO>(#248)} ‘lte(5, %1)’ -> ‘0’
    +Prefs Code Object <PrCO>(#248)} ‘ %1’ -> ‘3’
    

    Do I need to swap it around? Should be lte(%1, 5) ?


  • Coder

    Why not just do [gte ([match (1 2 3 4 5,%0)],1)]?


  • Tutorialist

    @Seamus said in WTF And?:

    Why not just do [gte ([match (1 2 3 4 5,%0)],1)]?

    Because I'm not very familiar with match(), I don't think I've ever used it. And indeed I figured out the problem was that I had the numbers backward. It needed to be gte/lte(%1, 0/5) for the logic to work right.


  • Tutorialist

    @Seamus said in WTF And?:

    Why not just do [gte ([match (1 2 3 4 5,%0)],1)]?

    But! Got any clever ideas on how to work with setting the data?

    It's currently stored like.

    _prefs.ratings: category:3.anothercategory:2.another:category:3

    I realized that set(%#, _prefs.ratings:[get(%#/_prefs.ratings)].%0:%1) won't work ... because what if they want to reset a pref they already have?

    I guess I'll have to add a thing in to see if that have that one set already... and then somehow replace it. :< (Oooooh, edit, will help there, yes, okay.)


  • Coder

    &fn`setstat <object>=[setunion([setdiff(<list of current stats>,<original stat>,<divider>)],<new stat>,<divider>)]

    That's a VERY VERY basic system for doing it.


  • Tutorialist

    @Seamus Yeah that's what I've ended up starting to build up. I'm trying to think if there's a more graceful way to do it. I want to use edit() but ... I'd have to take out the delimiter. :|


  • Coder

    Cobalt.

    lte( 5, 3 )

    Is 5 less than 3?


  • Tutorialist

    @Seamus Okay got any clue why this is being weird?

    &c.+prefs/set prco=$+prefs/set *=*:@pemit %#=[setq(p, pmatch(%#))]
    			[if(u(fn.iscat?, %0),
    				[if(and(lte(%1, 5), gte(%1, 0)),
    					[alert(+Prefs)] Setting %0 to %1.
    					[if(hasattr(%qp, _prefs.ratings),
    						[if(u(fn.hascat?, %qp, %0),
    							[alert(+Prefs)] Changing %0 to %1.[set(%qp, _prefs.ratings:[setdiff(get(%qp/_prefs.ratings), [graball(get(%qp/_prefs.ratings), %0, .)], .)].%0:%1)],
    							[alert(+Prefs)] Setting %0 to %1.[set(%qp, _prefs.ratings:[get(%qp/_prefs.ratings)].%0:%1)]
    						)],
    						[alert(+Prefs)] Setting %0 to %1.[set(%qp, _prefs.ratings:%0:%1)]
    					)],
    					[alert(+Prefs, alert)] You tried to set '%1'.  You must set a rating of 0 to 5.
    				)],
    				[alert(+Prefs, alert)] I'm sorry but '%0' is not a category.  Check +prefs/list for available categories.
    				)]
    

    It's returning:

    :.+Prefs.: Setting action to 2.:.+Prefs.: Changing action to 2.
    

    I feel like it's a case of a missing coma or parenthesis but for the life of me I can't find it. :|


  • Tutorialist

    It's... like it's calling the code twice.

    Mrrn.


  • Tutorialist

    Aaaaand I found it!

    Hello MSB! Welcome to "Cobalt knows what she's doing, honestly." masterpiece theatre.



  • ...You are all Heretics, and meddle with The Warp! BURN!

    shakes fist at


  • Coder

    @HorrorHound said in WTF And?:

    ...You are all Heretics, and meddle with The Warp! BURN!

    Hail Tzeentch!


Log in to reply
 

Looks like your connection to MU Soapbox was lost, please wait while we try to reconnect.