World: r3wp
[I'm new] Ask any question, and a helpful person will try to answer.
older newer | first last |
RobertS 26-Aug-2007 [765x3] | Can u tell me why we use datetype unset! in the func list-dir but not in the func to-logic I.e. why do we not have to logic! return false when I pass in it an unset! ? Or am I missing something here ? Maybe I miss what is the diff between 'qwetr being type set-word! and it not having a binding yet or my having sent unset 'qwetr Is this like the diff in other lang's between nil_or_null and undefined_or_undeclared ? |
oh I see listdir ; the param is not there, i.e., we have something unset! listdir qwetr ; errror But could the latter not return false a la negation-as-failure meaning I cannot browse your putative directory ? I guess I am asking " What is the Rebolesque way of seeing this? " | |
Say i have a: [ 1 b 2 ] now list-dir to-url a/2 a/2 ; b ; I see this as different from list-dir this-word_occurs _nowhere_in_this_context list-dir this-word-has-no-binding-yet-in-this-context to-logic a/2 ; this would be false to-logic a/qwetr ; i don't know what to think to-logic qwetr ; my question ( I thought ? ) | |
Ladislav 26-Aug-2007 [768x4] | hello RobertS, to-logic does not accept unset! value. Functions that accept uset! look as follows: my-func-accepting-unset: func [arg [any-type!]] [...] or func [arg [unset! ...]] [...], functions having the following spec: func [arg] [...] generally accept neither unset! nor error! |
so, if I wanted to patch to-logic I could write e.g.: to-logic: func [value [any-type!]] [ case [ ; taking care of #[unset!] not value? 'value [false] error? :value [true] true [to logic! :value] ] ] | |
HTH | |
(you can change the above definition to suit your needs) | |
RobertS 26-Aug-2007 [772] | thanx |
btiffin 26-Aug-2007 [773] | Robert; By definition in REBOL the only logical false values are #[false] and #[none] So for instance, integer! 0 is logcally true, which took me by surprise at first, but that is the way of REBOL. Surprise! Usually pleasant. :) Aside: The other words that evaluate as false; no, off (others?) do not have a pure lexical form so, #[off] is not a loadable value but the word off still evaluates to #[false]. And to logic! get/any 'an-unset-word will evaluate as #[true], as back to the defintion, only #[false] and #[none] are false. As far as I understand it anyway. |
Graham 27-Aug-2007 [774] | annoying .. can't use those forth tricks that require 0 to be false! |
btiffin 27-Aug-2007 [775] | It is kinda Born and raised with 0 false 1 true (actually being a polyFORTH coder) 0 false 1 true -1 really true. The whole all bits on argument. :) |
RobertS 27-Aug-2007 [776] | I have written an alternate form of the func WHAT that dumps to a file ( I have only 481 global functions at startup ) I will try to find time to build a page that gives clicks for SOURCE and HELP for each func in a given file dump (and maybe group them) I tried messing with PRINT but that broke HELP and SOURCE ;-) |
Gabriele 28-Aug-2007 [777] | you can also just: echo %somefile.txt - everything that is printed also goes to the file. echo none disables it. |
RobertS 29-Aug-2007 [778] | Thanks. btw I saw this on MAP on the Rebol3 group >> map [where:] [1 2 3 4 5 6] [take/part where 2] == [[1 2] [3 4] [5 6]] ; Graham said not too intuitive - I prefer the solution you suggested to me a few days back ; Will we have FOLD in Rebol3? If so, it should be intuitive, as should any MAP imho TAKE inside a MAP is counter-intuituve to me cuz MAP should not ;be slice-n-dice ... PARTITION/pairs PARTITION/triples partition/4 etc |
Gabriele 30-Aug-2007 [779x4] | i don't think one would use TAKE often with MAP or FOREACH. |
usually you just do something like map [a b] [1 2 3 4] [a + b] | |
a simple fold is: | |
fold: func [ "Applies F to the accumulator value and, successively, each value in the block." block [any-block!] "Block of values" accum "Accumulator value" f [any-function!] "Function to apply" ][ foreach val block [accum: f :accum :val] ] | |
RobertS 30-Aug-2007 [783x2] | ; Just FYI ... Ladislav Mecir has an excellent page on bind at http://www.fm.tul.cz/~ladislav/rebol/contexts.html But it does not warn you not to try >> someWord: make word! ":test:" >> print bind? 'someWord ; BAD IDEA I am fine with >> none? bind? 'someWord or >> equal? bind? 'someWord bind? 'someContext Printing the global context seems like a bad idea, at least when my PC is carrying a heavy load ;-) |
>> length? mold bind? 'rebol == 504310487 | |
Gabriele 31-Aug-2007 [785x2] | that's just like print system/words :-) since system/words contains system too, you are printing all of rebol. |
the size of that depends on what you've done in the session. if you started the view desktop for example, you're going to get quite a big result ;) | |
RobertS 31-Aug-2007 [787] | on another topic (how like me :-) >> source does ; leads naturally to >> source throw-on-error ; which is a good read ... for me, anyway |
Gabriele 31-Aug-2007 [788] | which should lead to investigate what the [catch] function attribute does :-) |
RobertS 31-Aug-2007 [789x12] | ; tutorials on series and find/part ; I may be alone in thinking that without experimenting, a newbie will miss this ... here is my experiment ; the docs say part will accept a 'range' but give no clear indication what a 'range' is in 2.x text: { Tested this before. Then test these. } start: find text "this" end: find start newline item: find/part start "this" end print item index? find text "this" index? start length? start index? end length? end head start head end index? item head item ; by now you get that Ah-Hah experience or Eureka! or 'hot-damn!' as the case may be ... |
; drat. That should be start: find text "ted" end: find start newline item: find/part start "this" end print item | |
; the docs say /part - Limits the search to a given length or position. range - The range argument. (must be: number series port) ; but it is not clear how to pass in that range argument as a 'position' let alone a series or port ; the only sign of something going wrong other than an error is that the 'end' is simply spit back out at the console, i.e., no error but bogus 'result'' | |
; last words of the horse thief on the gallows: 'It has all bin a lesson to me' >> equal? start end ; false >> equal? head start head end ; true | |
The simple thing to state would be that the 'range' option in question is precisly that same series, albeit with the current position shifted out further. >> item: find/part start "this" 24 >> item: find/part start "this" (find start newline) ; range as port ( I have not yet seen this ) | |
>> item: find/part start "this" my-port ; when range is port we must be reading 'start' from a data-source ( ? ) | |
ditto for copy/part As Newbie I have to realize that the 'series' mentioned in the HELP is that self-same series. | |
>> t: copy :end >> item: find/part start "this" t ; ERROR but not at all obvious; >> item: find/part start "this" "^/ Then test these.^/" ; ERROR even though true that >> equal? "^/ Then test these.^/" :end | |
I would have my tutorial read: some series S at some position that same series S at some further position And: think of 'find' as 'try to reposition current index in the series' Without seeing the source for FIND, I have no idea yet how to explain that 'range' must be that very same series. Chalk it up to lack of imagination... | |
; this now makes sense >> file: %image.jpg >> print copy/part file find file "." ; == "image" I will focus on this example in my tutorial but only AFTER >> fileName: "image.jpg" >> print copy/part fileName find fileName "." ; == "image" | |
; as a newbie I found this useful ... >> tt: "this is my test of X which will fix the XY thing" >> token: find/part tt "X" find tt "is" ; == none >> token: find/part tt "X" find tt "thing" ; == "X which will fix the XY thing" | |
; I did a dif between the functions in VIEW and those in CORE for a default install. What I get is this ( I hope it is useful to have al 106 in one place ) alert brightness? caret-to-offset center-face choose clear-face clear-fields confine crypt-strength? dbug deflag-face desktop dh-compute-key dh-generate-key dh-make-key do-events do-face do-face-alt do-thru draw dsa-generate-key dsa-make-key dsa-make-signature dsa-verify-signature dump-face dump-pane edge-size? editor emailer exists-thru? find-key-face find-window flag-face flag-face? flash focus get-face get-net-info get-style hide hide-popup hilight-all hilight-text hsv-to-rgb in-window? inform insert-event-func inside? install launch-thru layout link-relative-path load-image load-stock load-stock-block load-thru local-request-file make-face notify offset-to-caret open-events outside? overlap? path-thru read-net read-thru remove-event-func request request-color request-date request-dir request-download request-file request-list request-pass request-text reset-face resize-face rgb-to-hsv rsa-encrypt rsa-generate-key rsa-make-key screen-offset? scroll-drag scroll-face scroll-para set-face set-font set-para set-style set-user show show-popup size-text span? stylize textinfo unfocus uninstall unlight-text unview vbug view viewed? win-offset? within? | |
Gabriele 1-Sep-2007 [801] | range can be port only if you are searching a port too - but, not 100% sure how well that works. i bet it only works on buffered ports though. |
RobertS 3-Sep-2007 [802x3] | ; this is handy if you are new as am I >> foreach t (sort/compare datatypes func [a b] [ (form a) < (form b)]) [print mold t] |
I have nothing on END! other than parse ... to end ] | |
SYMBOL! is internal houskeeping for names of words (?) and a routine! is for working with a call to a DLL ( of my 54 datatypes in a 2.6.3 VIEW exec ) | |
Allen 3-Sep-2007 [805x4] | Robert you can get a similar list by doing |
? ! | |
or using "? datatype!" | |
not as much fun as exploring/learning with your own funcs, but help "?" can do some great things, including matching on datatype "? tuple!" is a quick way to lookup colours. | |
RobertS 4-Sep-2007 [809] | Thanks. And is that colours or colors? ;-) |
Allen 4-Sep-2007 [810] | ; interesting question ... Rebol lets me spell it "colour" if I really want to :-) alias 'color "colour" view layout [label with [colour: red] "hello"] |
btiffin 4-Sep-2007 [811] | Robert; Make sure you check out http://www.rebol.it/romano/and in particular http://www.rebol.it/romano/#sect1.1.anamonitor 3.0 and 2.0. Not something for your average I'm new resident but I have a feeling you'll appreciate Romano's utilities. |
RobertS 8-Sep-2007 [812x3] | Here is one of my first encounters with unset! when working on a tutorial to introduce console Rebol to someone who knows Common Lisp >> m: [1 2 3] == [1 2 3] >> m == [1 2 3] >> probe m [1 2 3] == [1 2 3] >> print mold m [1 2 3] >> mold m == "[1 2 3]" >> type? print mold m [1 2 3] == unset! >> type? mold m == string! >> type? probe m [1 2 3] == block! >> |
the answer is interesting for me as a newbie and lies in >> source probe | |
; the error from trying >> n: print mold m ; natually leads to help print ; and since this fails p: write %tmp.txt :anything" ; with help write ; we get to clarify binding words to values, functions, procedures evaluation and returned values ; I hope to get tutorials prepared for OCaml and Scheme as well as Haskell and Curl, Perl, Python, Ruby and Smalltalk based on my experience as a newbie while I am still a newbie ... | |
older newer | first last |