![list and recursion using visual prolog 5.2 list and recursion using visual prolog 5.2](https://wiki.visual-prolog.com/images/4/45/FundamentalVisualProlog2.png)
- #List and recursion using visual prolog 5.2 how to#
- #List and recursion using visual prolog 5.2 code#
The easy part for OCaml is that once you understand the idea of how to write functional programming and is good at thinking recursively, then OCaml will be relatively intuitive.ġ1. We use OCaml to test k=10 and n=20, and the running time for OCaml is joyfully the fastest, finished in 4 seconds.ġ0. Assign k and n by command line arguments and let our answer be cbn k (newList n), where newList is a list of size n.ĩ. Create two other functions newList and printList so that we can initialize a new list and can print it out later using printList function.Ĩ. At the very end of the function, concatenate list1 with list2.ħ. list2 will use cbn function and return with cbn k tl. That is, list1 will return all those that contains the head chosen.Ħ. We separate original list with head and tales, where list1 will prepend head in front of recursion cbn( (k-1) tl). If the list is empty, the match this empty list with. First define a recursive function named cbn in which it will call itself. OCaml is a functional programming language in which it's style uses a lot of function to define.Ĥ. This will cause a lot of compilation errors if we didn't get the syntax correct.ģ. Also, you have to put end if for if statement, and have to put end loop to says a for loop ends. It forces you to write begin and end for procedure and every functions. However, Ada is really picky about its syntax as I mentioned above.ġ1. The easy part for Ada is that it's really english oriented and really imperative, which makes it easier to learn and pick up.ġ0. We test the program using k=10 and n=20 as input, and the running time for Ada is about 6 seconds.ĩ. Run the cbn function and set it to Ret, although Ret value is always set to 0(because it's never written/read after firstly assigned)Ĩ. begin the main part by initializing k and n from command line argument, and N_Arr with size N and filled with 0.ħ. This function takes 4 parameters as input and will print out possible combinations with the for loop and recursion inside the function.Ħ. Before declaring functions, we need to declare all the variables we need before the function declaration.ĥ. The syntax needs to have procedure (like class in java).Ĥ. Ada is a programming language in which very picky about syntax. Sample command line for running this would beģ. Run the file combination.adb using gnatmakeĢ. My default shell is cshell while my partner's default shell is bash.ġ.
#List and recursion using visual prolog 5.2 code#
The code are all tested using the school cycle1 CSUG machine.
![list and recursion using visual prolog 5.2 list and recursion using visual prolog 5.2](https://img.youtube.com/vi/75GxxMTfs0Q/hqdefault.jpg)
TAs should be able to find every files under the A1 directory We also implement Java version of combinations as extra credit work Po-Chun Chiu's CSC 254 Assignment 1 Comparing Languages(Combinations) README