Message Boards Message Boards

0
|
5580 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:
GROUPS:

Difficulty to understand the block function

Posted 9 years ago

Hello,

I would like to better understand the block function. First, is it a recursive function ? I have read the help but I didn't well understand the operation of this function.

Here a an example where a Block function is used and that I would like to understand.

XMLtest = {
  XMLElement["YO", {}, 2], 
  XMLElement[  "BA", {},   {
        XMLElement["YO", {}, {
           XMLElement["BA", {}, 2]}],   XMLElement["BA", {}, 2]}]
  }

Here the use of the Block function

 XMLtest = 
  Block[{XMLElement}, 
   XMLElement[Except@"YO", _, {content__XMLElement}] := content; 
   XMLElement[Except@"YO", _, _] := Sequence[];
   XMLtest]

The created function permits to suppress the XMLElements different from YO as I wanted.

Why a Block function is used here ? What is the element which stops the loop ?

Thank you for your help.

POSTED BY: B B
2 Replies

Block and Module are tools for doing procedural programming with local variables. Block localizes them and Module renames them.

POSTED BY: Frank Kampas

This has been discussed already broadly elsewhere

Block is not are recursive function, in a way it is even not a function, but a scoping construct.

POSTED BY: Udo Krause
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract