phrep

Check-in [a1eb5d98ad]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add `qw@` macro for simple list generation from literal words.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:a1eb5d98ad00e75e081adb655f4a49721cc47b77
User & Date: mario 2015-04-28 23:06:10
Context
2015-04-28
23:06
Remove redundant //<?php prefix check-in: 223fc62a1b user: mario tags: trunk
23:06
Add `qw@` macro for simple list generation from literal words. check-in: a1eb5d98ad user: mario tags: trunk
2015-03-19
15:55
Cleanup examples. Use _pkgs/ output dir in Makefile. check-in: e995a45419 user: mario tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

cli.php became executable.

Changes to examples/defaults.ph.

1
2
3
4
5

6
7
8
9
10

11
12
13
14
15
16
17
18
19
20
21
22

23
24


25
26

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41





42
43
44
45
<?php
#pragma(output=0)




// Backwards-compatiblity

#if __PHP_VERSION__ < 5.3
 #define  __DIR__  dirname(__FILE__)
#endif




// Basic macros

#ifndef FLOAT_EQUAL
 #define FLOAT_EQUAL(f,g) (abs((f)-(g))<__FLT_EPSILON__)
#endif

#ifndef MAX
 #define MAX(a,b) ((a)>(b)?(a):(b))
#endif






// Complex macros (AKA "shield operator" decorations)


#define IFSET@(expr)						\
  {  return "(isset($expr) ? $expr : NULL)";  }

#define COALESCE@(args...)					\
  {  return "reset(array_filter(".var_dump($args,1)."))";  }

#define NULLSAFE@(expr)						\
  $expr = preg_split("/\s*->\s*/", $expr);			\
  $r = "(\$_ = " . array_shift($expr) . ")";			\
  foreach ($expr as $x) {					\
    $r .= " and (\$_ = \$_->$x)";				\
  }								\
  return "($r ? \$_ : NULL)";








#pragma(output=1)
?>




<
>
|
|
<
<
<
>

<
<
<
<
<
|
<
<
<
|
<
>


>
>
|
<
>




<
<
<








>
>
>
>
>


<
<
1
2
3
4

5
6
7



8
9





10



11

12
13
14
15
16
17

18
19
20
21
22



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37


<?php
#pragma(output=0)



/**
 * Basic macros
 *



 */






#define FLOAT_EQUAL(f,g) (abs((f)-(g))<__FLT_EPSILON__)



#define MAX(a,b) ((a)>(b)?(a):(b))

#define SWAP(a,b) list(b,a) = array(a,b)


/**
 * Complex macros (AKA "shield operator" decorations)
 *

 */

#define IFSET@(expr)						\
  {  return "(isset($expr) ? $expr : NULL)";  }




#define NULLSAFE@(expr)						\
  $expr = preg_split("/\s*->\s*/", $expr);			\
  $r = "(\$_ = " . array_shift($expr) . ")";			\
  foreach ($expr as $x) {					\
    $r .= " and (\$_ = \$_->$x)";				\
  }								\
  return "($r ? \$_ : NULL)";

#define qw@(words)						\
  return "[" . join(", ",					\
     array_map(function($w) { return var_export($w, TRUE); },	\
       preg_split("/\s+/", trim(\io\Token::join($token))))	\
    ) . "]";