blob: 9689227f88597d45c4457e8e3baa5cced82c48ca (
plain)
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
|
str alphcount( Str: str )
= c_alphcount
print "[alphcount( " hello friend " )]
##### CALL #####
#include <colm/tree.h>
#include <colm/bytecode.h>
#include <stdio.h>
#include <string.h>
str_t *c_alphcount( program_t *prg, tree_t **sp, str_t *a1 )
{
int p, count = 0;
for ( p = 0; p < a1->value->length; p++ ) {
char c = a1->value->data[p];
if ( 'a' <= c && c <= 'z' )
count++;
}
char strc[64];
sprintf( strc, "%d", count );
head_t *h = string_alloc_full( prg, strc, strlen( strc ) );
tree_t *s = construct_string( prg, h );
colm_tree_upref( prg, s );
colm_tree_downref( prg, sp, a1 );
return (str_t*)s;
}
##### EXP #####
11
|