Use another language to call a function: Difference between revisions
Content deleted Content added
added ocaml |
Add new section for Lisaac |
||
Line 66: | Line 66: | ||
</pre> |
</pre> |
||
=={{header|Lisaac}}== |
|||
query.li |
|||
<lang Lisaac> |
|||
Section Header |
|||
+ name := QUERY; |
|||
- external := `#define main _query_main`; |
|||
- external := `#define query Query`; |
|||
Section External |
|||
- query(buffer : NATIVE_ARRAY[CHARACTER], size : NATIVE_ARRAY[INTEGER]) : INTEGER <- ( |
|||
+ s : STRING_CONSTANT; |
|||
+ len, result : INTEGER; |
|||
s := "Here am I"; |
|||
len := s.count; |
|||
(len > size.item(0)).if { |
|||
result := 0; |
|||
} else { |
|||
1.to len do { i : INTEGER; |
|||
buffer.put (s @ i) to (i - 1); |
|||
}; |
|||
size.put len to 0; |
|||
result := 1; |
|||
}; |
|||
result |
|||
); |
|||
Section Public |
|||
- main <- ( |
|||
+ buffer : NATIVE_ARRAY[CHARACTER]; |
|||
+ size : NATIVE_ARRAY[INTEGER]; |
|||
query(buffer, size); // need this to pull the query() method |
|||
); |
|||
</lang> |
|||
Makefile |
|||
<lang make> |
|||
TARGET=test_query |
|||
all: $(TARGET) |
|||
$(TARGET): main.o query.o |
|||
gcc -o $@ main.o query.o |
|||
.c.o: |
|||
gcc -c $< |
|||
query.c: query.li |
|||
-lisaac $< |
|||
clean: |
|||
rm -f $(TARGET) *.o query.c |
|||
</lang> |
|||
=={{header|OCaml}}== |
=={{header|OCaml}}== |