r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[Core] Discuss core issues

Chris
28-Jun-2008
[10719x2]
Paul: it's a common enough pattern, I'd like to find the most appropriate 
way to express it.  Actually, that's the principle behind QM (which 
of course, this is intended for).  The alternative case above would 
be:

	case [
		not a < 10 [print "a is more than 10"]
		not result: a > 0 [print "a is less than 0"]
	]
	result


Requires a 'not statement for each test, requires an extra word to 
track the result and does not return a meaningful value.  Consider 
this:

	if assert-all [

  user/has-role? 'editor [make error! "You do not have required permission"]
		article: get-param 'article [redirect-to %/articles/create]
		10'000 < length? article [make error! "Article is too long"]
	][
		save %article.txt article
		redirect-to %/articles/list
	]
Henrik, how does your scenario differ?  Do you have a sample of your 
solution at work?
Henrik
28-Jun-2008
[10721]
I had a function that does this a while ago, but I have to dig it 
up
Chris
28-Jun-2008
[10722x3]
Graham, I'm still pondering naming.  'assert seems to evoke unit 
tests, that's not what this is.  'all-nots doesn't quite get the 
essence either.  'all-else is a possibility?  Until then, I still 
lean toward 'assert-all.
H: is this the type of problem you were addressing?
That is, I have a series of tests, each requiring a case for failure...
Henrik
28-Jun-2008
[10725]
Chris, I guess it could work.
Chris
28-Jun-2008
[10726]
I'm curious re. approach, expression and naming...
Henrik
28-Jun-2008
[10727x2]
found it, but I remember it being more elegant than the code I found 
here...
sorry, it does not work very well. I think I would build a new one 
from scratch if I needed it again.
Chris
28-Jun-2008
[10729]
I get that -- a sign of personal progress, perhaps?
Henrik
28-Jun-2008
[10730]
well, I tried a single line of code with it, and it didn't do what 
I wanted. I guess I could ask myself if I would write that kind of 
code today. :-)
[unknown: 5]
28-Jun-2008
[10731]
Chris - 'case is native so even adding a 'not statement is going 
to be faster solution I think.
Graham
28-Jun-2008
[10732x2]
Should one go for speed or readability?
If it's a time critical app like a web server I'd go for speed ...
Chris
28-Jun-2008
[10734x3]
Readability.  I want it to be fast, of course, but long-term it's 
not worth the compromise.  I want to do more with less.
Indeed 'all would be fastest yet, except you don't get feedback at 
the point of failure.
You could use 'foreach which'd be fast, but then you'd have to block! 
your case as well as your fallback losing readability.
Janeks
30-Jun-2008
[10737]
I am working on sript, that composes and sends html e-mail.

It is rather simple, but now I would like that e-mail will contain 
inline images.

I found out that they are multipart messages, and that image is referenced 
with cid in html image and in image part it is marked as Content-ID:

</HEAD>
<BODY bgColor=3D#ffffff>

<DIV><FONT face=3D"Courier New" size=3D2></FONT><IMG height=3D47=20
src=3D"cid:26DB76551F2E4591BBC3B599C3A7CCAE" width=3D320></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT>&nbsp;</DIV>
</BODY></HTML>

------=_NextPart_001_00A9_01C8DAAB.A817E460--

------=_NextPart_000_00A8_01C8DAAB.A817E460
Content-Type: image/bmp;
	name="ML.bmp"
Content-Transfer-Encoding: base64
Content-ID: <26DB76551F2E4591BBC3B599C3A7CCAE>


Qk22vQEAAAAAADYAAAAoAAAADwIAAEgAAAABABgAAAAAAIC9AQDEDgAAxA4AAAAAAAAAAAAA////

////////////////////////////////////////////////////////////////////////////

How to implement such html e-mail generation in rebol script?
Graham
30-Jun-2008
[10738]
the send/attach can generate the multipart components for you.
Janeks
30-Jun-2008
[10739]
O'k. But how to put Content -ID into message part?
Gregg
30-Jun-2008
[10740]
Alan Dechert <[dechert-:-gmail-:-com]> asked the same thing on the ML earlier 
this month. Maybe the two of you can collaborate on a solution. If 
you could enhance SEND to allow it, maybe with a new refinement, 
we can try to get Carl to make it the standard.
Graham
1-Jul-2008
[10741x3]
Anyone know how to use sort on some data where eg. skip value is 
10 and you want to sort of anything but the first element?
Looks like the comparator function takes two arguments ... which 
are the first of each set
Ok, sussed it out .. the compare can be an integer offset
Janeks
2-Jul-2008
[10744]
What is the right way to check  is port (ODBC, mySQL) open?
Is it a-port/port-id ?
Gregg
2-Jul-2008
[10745]
There's no official way. I think DocKimbel had a value in flags or 
state that he said worked. If he doesn't jump in, I'll dig for it.
james_nak
2-Jul-2008
[10746]
Janeks, Dockimbel recently put some code in the MySql group regarding 
how to check for Mysql port being opened.
Henrik
7-Jul-2008
[10747]
has anyone worked on a method to convert a rebol block to a php array 
inside php?
Dockimbel
8-Jul-2008
[10748x3]
For checking if a port! value is "opened", you can use this function 
: open?: func [port][zero? port/state/flags and 1024]. But that just 
checks for the "close" flag, it doesn't check the real TCP connection 
state.
>> p: open http://rebol.com
>> open? p
== true
>> close p
>> open? p
== false
In this example, it does report correctly the port state, but that 
doesn't inform you about the underlying TCP connection state (the 
TCP connection is closed once the first line is completed).
TimW
9-Jul-2008
[10751]
Is there a way to specify precision with rounding?   My specific 
example has to do with money.  Not only does it always chop it off 
to exact cents, but it rounds down.  so .125 -> $0.12   This is horrible 
for accounting purposes.  I just put everything in decimal and completely 
ignore the money! datatype, but this seems like a real shame.  So 
is it possible to specify the decimal out to 4 or 5 places?
Graham
9-Jul-2008
[10752]
help round
TimW
9-Jul-2008
[10753]
'round still doesn't work with money though >> round/to to-money 
.125 .001  --> $0.12
Henrik
9-Jul-2008
[10754]
Tim, it's probably better to not use money! when rounding.
Sunanda
9-Jul-2008
[10755x2]
The rounding may not be to exact cents -- money type only *displays* 
2 decimal points, though it *preserves* more:
   to-money .125
   == $0.13
   second to-money .125
   0.125
Also, I am not seeing the always-down effect you report.
   round/to $.125 .001
   == $0.13    ;; correctly rounded up


Round did go through a couple of development stages. Perhaps your 
version of REBOL has an outdated one. This is the source from the 
version I am using:

round: func [

    {Returns the nearest integer. Halves round up (away from zero) by 
    default
.}
    [catch]
    n [number! money! time!] "The value to round"
    /even "Halves round toward even results"

    /down {Round toward zero, ignoring discarded digits. (truncate)}
    /half-down "Halves round toward zero"
    /floor "Round in negative direction"
    /ceiling "Round in positive direction"
    /half-ceiling "Halves round in positive direction"
    /to "Return the nearest multiple of the scale parameter"
    scale [number! money! time!] "Must be a non-zero value"
    /local m
][
    throw-on-error [
        scale: abs any [scale 1]
        any [number? n scale: make n scale]
        make scale either any [even half-ceiling] [
            m: 0.5 * scale + n
            any [
                all [
                    m = m: m - mod m scale
                    even
                    positive? m - n
                    m - mod m scale + scale
                ]
                m
            ]
        ] [
            any [
                floor
                ceiling

                (ceiling: (found? half-down) xor negative? n down)
                n: add n scale * pick [-0.5 0.5] ceiling
            ]

            either ceiling [n + mod negate n scale] [n - mod n scale]
        ]
    ]
]
Henrik
9-Jul-2008
[10757]
As a note: In R3, money! is of much greater precision (infinite?) 
and should round properly using conventional ROUND/TO (once bug #492 
is fixed, that is :-)).
Pekr
9-Jul-2008
[10758]
infinite = 27 positions, IIRC ...
Henrik
9-Jul-2008
[10759]
thanks, couldn't remember
Chris
13-Jul-2008
[10760x2]
Uck, this is unsightly:

	>> to-path [
	[    a
	[    b
	[    c
	[    ]
	==
	a/
	b/
	c
Why does it not result in:

	== a/b/c
[unknown: 5]
13-Jul-2008
[10762x2]
The newline character is being detected so it is treating each as 
a separate statement.  I would think that isn't a bug but rather 
a feature.
Since the following works fine:

>> to-path [a b c]
== a/b/c
Chris
13-Jul-2008
[10764x4]
I think it's a bug in to-path.  Why would you possibly want to retain 
that behaviour?
I can understand silently storing newline settings between block 
sessions (I use 'new-line a little to control this behaviour), but 
what scenarios benefit from this when working with paths?
Consider this scenario:

	countries: [
		us "United States"
		fr "France"
		au "Australia"
		uk "United Kingdom"
	]

	foreach code extract countries 2 [
		probe form to-path compose to-block 'users/(code)
	]
I know how to work around it, just don't see the purpose.
Gabriele
14-Jul-2008
[10768]
chris, there is no purpose, it's just that internally path! = block!, 
so path! behaves exactly like block! does. it probably should strip 
newlines when converting though, or at least ignore them when molding... 
(that is, i'm saying this is a bug.)