[REBOL] [REBOL] [REBOL] Redefining functions with objects Re:(4)
Hi Ingo: In reply to your statement: When your 'op was named 'open, did you change the line fp: open/new/write %objone.txt to fp: system/words/open/new/write %objone.txt - ?? otherwise it has called itself, again and again ... I didn't - and that's why I got a stack overflow, because of unending recursion. Thanks! I'm glad you caught that! Tim At 01:20 PM 4/12/00 +0200, you wrote: Hi Tim, I haven't closely looked at your code, but a short notice on ... Those were the words of [EMAIL PROTECTED]: I have probably answered my own question: I'm still a newbie, but am pleased to return results - ; == consider the following code: the two objects work ; independently. They use the same named methods ; op, prn, and close ; When I named those methods open, print,and close, ; I got stack overflows, which suggests to me ; that rebol doesn't like me overridding their ; own system functions. ... object-one: make object! [ op: func [] [fp: open/new/write %objone.txt] prn: func [value] [append fp value] cls: func[] [close fp] ] -- _ ._ ingo@)|_ /| _| _ We ARE all ONE www._|_o _ _ ._ _ www./_|_) |o(_|(/_ We ARE all FREE ingo@| |(_|o(_)| (_| http://www.2b1.de/Rebol/ ._| ._|
[REBOL] [REBOL] Redefining functions with objects Re:
Hi Tim, Will tims-object/print redefine rebol's own print? Within tims-object print replaces the global print, which you can continue to access using system/words/print tims-object: make object! [ print: func [][ system/words/print "this is the global print." ] ] tims-object/print this is the global print. Outside of the object's context print is not affected by your re-definition of print in the object. ;- Elan [: - )]
[REBOL] [REBOL] Redefining functions with objects Re:(2)
Hi Michael - At 12:42 PM 4/11/00 -0700, you wrote: I'm currently defining a 'print element of an object as a function. I'm assuming that the REBOL definition of 'print will be hidden in the definition of this object (and definitions of functions local to the object) Actually . print would write to a port, which could be standard output OR a physical file. The port would be defined as a member of the object as well. let's call this content-object ; will build virtual ; pages OR could be used to build a physical web page ; let me know what you think of the following: ; thanks for your interest :) ; tim content-object: make object! [ write_to_file: func [] [ ; is this being run from a server? either equal? system/options/cgi/server-name none [return true] [{else}return false] ] init_output: func[fname[string!] /local fpl] [ either write_to_file ; no server so open a write port ; to fname [ file_name: make file! fname fp1: open/new/write file_name ] ; yup, we're on the server so keep writing to stdout [{else} fp: system/ports/output] return fpl ] ; what the hay!! We can call this anything, but ; print would be great if it didn't screw up implicit ; output to stdout for the "original print" fp: init_output "hello.htm" print: func [fp[port!] value] [append fp value] ] ; If this process works with out conflict, then I would ; create a debug object which would write to a file that ; would be created every time the application runs ; and an errorlog object that would be appended every ; time the application ran, given an error or warning ; condition appeared. Standard parts of the my C/C++/CGI ; toolkit and expected by sysops that my cgi programs ; run on. They could all have a print element (method) ; OR I could call it something else. - which is ok. Outside of the element 'print, the REBOL definition works just fine. Following is the relevant piece of my object: player-def: make object! [ name: none connection: none ; METHODS ; - - - - - - - - - - - - - - - - - - - - - - print: function [ "Print a message to this player, with trailing new-line" msg [string! block!] ][new-msg][ ; Cleanup the message suitable for telnet display new-msg: player-format-print msg append new-msg new-line append connection new-msg ] ; - - - - - - - - - - - - - - - - - - - - - - prin: function [ "Print a message to this player" msg [string! block!] ][new-msg][ ; Cleanup the message suitable for telnet display new-msg: player-format-print msg append connection new-msg ] ] - Michael Jelinek -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Tuesday, April 11, 2000 11:32 AM To: [EMAIL PROTECTED] Subject: [REBOL] [REBOL] Redefining functions with objects I'm thinking of developing a class. Let's call it tims-object Suppose I write a function for this class and I call it print Will tims-object/print redefine rebol's own print? I don't really want to do this, so I would welcome comments on this. thanks tim
[REBOL] [REBOL] [REBOL] Redefining functions with objects Re:(2)
I have probably answered my own question: I'm still a newbie, but am pleased to return results - ; == consider the following code: the two objects work ; independently. They use the same named methods ; op, prn, and close ; When I named those methods open, print,and close, ; I got stack overflows, which suggests to me ; that rebol doesn't like me overridding their ; own system functions. ; I'm happy with the result. Less typing eh! REBOL [ Title: "object" Date: 011-Apr-2000 File: %object.r Purpose: {testing rebol objects} ] ;=== make first object object-one: make object! [ op: func [] [fp: open/new/write %objone.txt] prn: func [value] [append fp value] cls: func[] [close fp] ] ;=== make first object object-two: make object! [ op: func [] [fp: open/new/write %objtwo.txt] prn: func [value] [append fp value] cls: func[] [close fp] ] ;=== test first object object-one/op object-one/prn "testing object-one once more" object-one/cls ;=== test second object object-two/op object-two/prn "testing object-two once more" object-two/cls At 05:10 PM 4/11/00 -0800, you wrote: Hi Michael - At 12:42 PM 4/11/00 -0700, you wrote: I'm currently defining a 'print element of an object as a function. I'm assuming that the REBOL definition of 'print will be hidden in the definition of this object (and definitions of functions local to the object) Actually . print would write to a port, which could be standard output OR a physical file. The port would be defined as a member of the object as well. let's call this content-object ; will build virtual ; pages OR could be used to build a physical web page ; let me know what you think of the following: ; thanks for your interest :) ; tim content-object: make object! [ write_to_file: func [] [ ; is this being run from a server? either equal? system/options/cgi/server-name none [return true] [{else}return false] ] init_output: func[fname[string!] /local fpl] [ either write_to_file ; no server so open a write port ; to fname [ file_name: make file! fname fp1: open/new/write file_name ] ; yup, we're on the server so keep writing to stdout [{else} fp: system/ports/output] return fpl ] ; what the hay!! We can call this anything, but ; print would be great if it didn't screw up implicit ; output to stdout for the "original print" fp: init_output "hello.htm" print: func [fp[port!] value] [append fp value] ] ; If this process works with out conflict, then I would ; create a debug object which would write to a file that ; would be created every time the application runs ; and an errorlog object that would be appended every ; time the application ran, given an error or warning ; condition appeared. Standard parts of the my C/C++/CGI ; toolkit and expected by sysops that my cgi programs ; run on. They could all have a print element (method) ; OR I could call it something else. - which is ok. Outside of the element 'print, the REBOL definition works just fine. Following is the relevant piece of my object: player-def: make object! [ name: none connection: none ; METHODS ; - - - - - - - - - - - - - - - - - - - - - - print: function [ "Print a message to this player, with trailing new-line" msg [string! block!] ][new-msg][ ; Cleanup the message suitable for telnet display new-msg: player-format-print msg append new-msg new-line append connection new-msg ] ; - - - - - - - - - - - - - - - - - - - - - - prin: function [ "Print a message to this player" msg [string! block!] ][new-msg][ ; Cleanup the message suitable for telnet display new-msg: player-format-print msg append connection new-msg ] ] - Michael Jelinek -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Tuesday, April 11, 2000 11:32 AM To: [EMAIL PROTECTED] Subject: [REBOL] [REBOL] Redefining functions with objects I'm thinking of developing a class. Let's call it tims-object Suppose I write a function for this class and I call it print Will tims-object/print redefine rebol's own print? I don't really want to do this, so I would welcome comments on this. thanks tim