head> COMP 590 Assignments Page

UNC-CH COMP 590-059

Class Assignments

As noted in class, you may work alone, or as a team of up to 3 people. Please submit ONE assignment per team, and make sure all team members are named clearly at the top of the work materials.



Assignment FE: Final Exam

Due Sat. Dec 9, 11:00 pm

Work on your own... no group work on this.

Consider the programming language Rust.

Write a report (PPT presentation, see below) discussing the following issues about Rust. These are issues and topics we have looked at with the other languages we have studied this semester:

  1. History: Who created your language? When? Any fun stories around its creation?

  2. Purpose: What is the intended purpose for creating the language? What issues or problems did the creator(s) hope to address or improve?

  3. Programming style: How is the language described? Imperative? Functional? OO? Declarative? Concurrent? Multi-paradigm? Some combination?

  4. Execution: Is the language compiled to each platform? Compiled to some "byte code" and run on a VM? Interpreted? Some combination? It is WORA (write once, run anywhere)?
  5. Objects: Does it have an object and/or class model? If so, describe it. How does it work? What is it similar to, and how is it different or unique (if it is)?

  6. Typing: How is the language typed? Does it do type inference? Explain a bit about the programmers experience when coding and managing types.

  7. Scoping: How is visibility of names handled in the language? Is scoping static or dynamic? What are the major lexical divisions in a program (blocks, functions, modules, classes, namespaces, etc.)

  8. Functional: Is there a functional emphasis? If so explain. Is it referentially transparent? Single assignment? Is evaluation lazy or eager? Are functions first-class entities? Can you create closures? Explain anything unusual about the funtional nature of the language.

  9. Concurrency: If the language is made to allow concurrent programs, explain the concurrency model. Will it handle a few large processes? Will it handle thousands of small processes? Shared state? Message passing?

  10. Example code: Show a couple examples or programs in your selected language. Make them non-trivial but pages of code are not needed. You do not have to write these yourself (but you may wish to).

  11. Anything else? Anything else interesting or different about the language? Explain.

Write your report as a PPT slide deck and submit to Sakai. Not one slide, not 80 slides... maybe 15-30 slides, whatever it takes to tell the story. Work on your own (no group work). In a class like this (seminar style) we would have presentations... if the size was also seminar size. But just the PPT will do with 40 people.



Assignment 8: Go programming

Due Monday 12/4 (11:00pm)


In this assignment we will do some Go proramming. Team work is fine on this.

You have installed Go on your computing platform. You have looked over the class notes, and the reading materials. You have tried writing basic Go.

Now, for submission, lets do some more advanced Go programming. Write a solution to the Sleeping Barber problem in Go. Put your code into a zip file for submission. Make sure to identify all of your team members for proper credit.


Assignment 7: Elixir programming

Due Monday 11/13 (11:00pm)

In this assignment we will do some basic Elixir proramming.

a) First, install Elixir on your computing platform. Look over the class notes, and the reading materials. Figure out how to compile and run basic Elixir code, both in the iex shell and also using the compilers elixir and elixirc.

b) Then, for submission, write the 3 smaller Erlang programs from Assignment 4 and Assignment 5 as Elixir programs.

Put the Elixir source code files into a zip file for submission. Make sure to identify all of your team members for proper credit.


Assignment 6: Erlang Sleeping Barber

Due Wed 11/1 (11:00pm)

In this assignment we will write an Erlang program that solves the Sleeping Barber problem we programmed in Java.

Feel free to use the Dining Philosophers Erlang solution posted in your class materials to help you make a solution.


Assignment 5: Erlang processes program

Due Wed 10/25 (11:00pm)

In this assignment we will write an Erlang program that spawns several processes to cooperatively solve the problem.

Write an Erlang program that will use the "send_recv" module we discusses in the video as a pattern or guide. You will write a chain of 3 "servers" which are processes that are in a chain communication pattern. Lets call for this discussion the servers serv1, serv2, and serv3. The head of the chain is serv1, which will be communicating with serv2; serv2 will communicate with serv3. The serv1 process will receieve messages (from the main function) and possibly send what it received on to serv2. The serv2 process will receieve messages from serv1 and possibly send what it received on to serv3; likewise, the serv3 process will receieve messages from serv2 but will not send any messages onward.

The basic specs are these:

-- all 3 server processes run potentially "forever" (except each will end when a halt message is received)

-- each one will examine messages it receives looking for ones that
   it knows how to handle; on finding one, it will processes it as
   its job requires;  if a message does not match the pattern(s) 
   that it handles, the server process will pass that message down the chain.

-- serv1 will do much like the math servers from our example code.  It will intercept messages
   that are tuples of size 3 or size 2.  A size 3 tuple will have the first component the atom
   'add', 'sub', 'mult' or 'div', and the rest of the message will be 2 numbers.  Perform the
   indicated arithmetic operation with component 2 the left operand and component 3 the right operand.
   In addition, a size 2 tuple will have the first component the atom 'neg' or 'sqrt' and the second
   component the numbers to apply the appropriate operation on.  For all messages, print an informative
   message indicating the operation, the operands, and the result.
   If the message does not match any of these patterns, then send the message on to serv2. 

-- serv2 will intercept mesages that consist of lists, where the head element in the list
   is a number. if that number is an integer, then print out the sum of all elements in
   the list that are numbers.  If the head element of the list is a float, then compute and
   print the product of all the numbers in the list (integer or float).
   If the message does not match any of these patterns, then send the message on to serv3.

-- serv3 will get all the messages that the processes earlier in the chain
   dont want to handle.  If the message is a tuple of size 2, with the first component
   the atom 'error' then print "Error: " and the second component of the message tuple.
   For any other message keep a running count of the unprocessed messages.  Simply print out 
   "Not handled: " followed by the message; also bump up the unprocessed message count.  To do 
   this you will need an accumulator that you pass to each successive recursive server call.  
   This means the serv3 function you make into a process will use a helper recursive function 
   that takes one parameter (the accumulator) and starts with 0 as that parameter.

-- each server process is doing some printing.  Any output they make should have the first 
   part indetify the process doing the writing -- something like "(serv1) whatever the 
   output text is..."

-- in addition to the various different message patterns each server process will watch for,
   all 3 processes will also respond to a shut down message.  The message will be the single atom
   'halt' and the server behavior will be to forward the 'halt' message down the chain, then print 
   out that it is halting, and finally end its own execution (meaning do not recurse for more 
   message handling).  For the end of the chain, the serv3 process, which is counting all messages 
   not processed, print a note with the value of that counter before doing its halt sequence,


The main function (let's call it "start/0") will repeatedly as the user to type a message as input, and will send the message to serv1 at the head on the chain. If the user types the atom 'all_done' then the main start function will end execution.

Feel free to embellish the program as you wish. Have fun with it.

You may work alone, or in groups of up to 3. In group work, the group produces a common solution and one group member submits the entire solution on behalf of all the group members. Put an erlang comment in your module source files naming all the group members, or naming the solo person doing the work. Put your source files into one zip file, and in Sakai, submit this single zip file.




Assignment 4: Simple Erlang program

Due Sunday 10/15 (11:00pm)

In this assignment we will get Erlang running on your computers, and then write two simple Erlang programs.

Follow the instructions to get Erlang installed on your laptop or other computer. Try the examples we have looked at in class, and get used to making source modules (with the .erl file type). Make sure you move around in the file system using the unix-ish "cd", "pwd", and "ls" commands; make sure you can compile the modules; make sure you can run the functions defined and exported by those modules.

Here is a short new erlang lesson: getting input from the keyboard. This is a small function that will get a number from the keyboard, and you may use this as you wish in the programs you write:

    get_numData() ->
        {ok, Num} = io:read("Enter a number: "),
        io:format("The number you entered is: ~w~n", [Num]).
This works using pattern matching, where the number typed by the user is bound to "Num" on the left side of the expression using io:read.

Once this all works, write these two Erlang programs. You can put them both in one module, along with any supporting functions; or if you would rather, you can write two different modules:

  1. Write an Erlang program that will take one number as input (you will get the number from the user typing it at the keyboard) and then do this computation:
    
    a) if the input is not an integer, print "not an integer"
    
    b) if the input integer is negative (smaller than 0), compute
       the absolute value of that integer raised to the 7th power... and print that.
    
    c) if the input integer is 0, simply output the 0
    
    d) is the input integer is greater than 0 then decide if it is a multiple
       of 7 or not; if it is a multiple of 7, print out the 5th root of the
       integer; if its not a multiple of 7, then print out the factorial 
       of that integer.
    
    It ends after doing the correct thing with the input number. You may find math:pow(X,Y) useful... it returns a float, and it computed X raised to the Y power. Factorial is a function we defined in class (in a PPT).

  2. Use the program just written as a "loop" body, and repeat the get-input-then-compute cycle repeatedly. End this repetition when the user gives a 0 as input.
    Note that you should do the "looping" here with tail recursion.

You may work alone, or in groups of up to 3. In group work, the group produces a common solution and one group member submits the entire solution on behalf of all the group members. Put an erlang comment in your module source files naming all the group members, or naming the solo person doing the work. Put your source files into one zip file, and in Sakai, submit this single zip file.





Assignment 3: Concurrency Coding

Due Wed 10/11 at 11:00pm

You may work in groups of up to 3 Write your own code… do not look up a web solution and copy it… learning comes from thinking it through When done submit in Sakai a single zip file. The zip file will contain 2 folders, one for Dining Philosphers, and another for Sleeping Barber. In each problem folder you will have the Java source code files, and a document with the discussion.

  1. Write a Java threads program to implement a solution to the Sleeping Barber problem.

  2. Do the same for the Dining Philosophers problem.





Assignment 2: OO Pillars and Models

Due Wed 10/4 11:00 pm

Prepare a zip file to submit in Sakai. The zip file will contain a folder, and the folder will contain Java source files, and a document that has answers to the discussion questions below.
Submit the zip file in Sakai for Assignment 2.

Remember to identifiy all team members on the paper.

  1. Write a Java program (not super long, but complete, and non-trivial) that exemplifes all the OO pillars:

  2. Pick a language from this list and explain its object model (like I did with Java and Javascript); how is each pillar expressed in the language you picked? What forms of polymorphism does it allow?






Assignment 1a: Using ChatGPT as high-level compiler

Due for class Tuesday 9/19

Please use class time today to get into teams and consider this:

How can we use ChatGPT (or other large language model, generative AI)
as a sort of "high-level" or abstract compiler?

Can we give specs to it that are "informal" (in English) and
get it to generate specific, executable code?

We know we can in some ways... in that if we ask it to write a bubble sort
in C++ it will.  It has basically "memorized" all the code out there
and does matches as best it can.  

There is more trouble if we ask it to write code for something
that does not have a canned name (like bubblesort).  We are left 
trying to write a prompt that has enough information in it about
what we want, and is unambiguous enough, to get working code
that meets our needs.

So we still have a situation similar to using Guttag's method for
ADT specs.  We are trying to be as formal as we can without 
just writing detailed code ourselves.

==============

The point of our exploration of Guttag's method for algebraic axioms
for ADTs has been to formally specify some computational behavior
without getting into details of any particular programming language
or implementation structure.  We want a specification notation that 
is mathematically manipulable and unambiguous (informal English is 
neither).

We are also then using SML as a vehicle for implementing such abstract 
algebraic specs because the translation from axiomns (in functional 
notation) into functional code is fairly straightforward.

But we could code from formal specs into other languages.

Try using ChatGPT as our "compiler" from formal specs to code.

Try getting ChatGPT to write SML code for things like the ADTs we 
are working with... Stack, Queue, MAP, etc.

Also try it with ADTs that are not well-known by name... maybe
Bounded Stomp Stack ... or make up some different ADT of your own
and see if you can get the code by giving the axioms as specs.

Come to class Tuesday next week with some examples we can discuss.
Perhaps capture your ChatGPT interactions in a text file which you
have on the web someplace so we can project it and discuss it.  

Assignment 1: Using ML to express ADT Axioms

Due Wednesday 9/20 (10:00pm)

You will be writing ML code (as we did in class) to implement ADT axioms for several ADTs. Use the method we looked at in class for encoding them in ML. For some of these, I give you axioms and you simply encode them into ML. For some I ask you to write the axioms as well as encode them into ML.

For the SML code, just use datatype definitions (for canonical ops) and partial function defintions (for non-canonical ops). Also exceptions and basic SML stuff. Don't use more complicated module features like signatures, etc. Let's just stick to the basics like the class examples.

Include test code with each SML implementation... in other words, "prove" to me the semantics of the ADT are correct and the implementation works properly.

  1. QUEUE ( https://www.cs.unc.edu/~stotts/COMP590-059-f23/FUNC/adtML/FIFO.html )
    Write and test ML encodings for these axioms. Make it polymorphic, i.e., a QUEUE of any type (not just QUEUE of int, for example).

  2. MAP ( https://www.cs.unc.edu/~stotts/COMP590-059-f23/FUNC/adtML/map.html )
    Write and test ML encodings for these axioms. Make it polymorphic.

  3. SET of E
    For this one, write axioms, and then write ML for them. Make it polymorphic.

    the operations in SET : new, add, rem, mem, card
    new makes an empty SET
    add put an element of type E into a set
    rem takes an element of type E out of the set
    mem (member) tells if a particular element of type E is in the set or not
    card (cardinality) gives the number of items in the set
    Remember the semantics of normal sets. When you add an item to a set and the item is already in the set, you do not change the set membership. The item is still in the set after the add... there is no notion of adding a second instance of the item.

  4. MSET of E
    For this one, write axioms, and then write ML for them. Make it polymorphic.

    MSET is a multiset (or Bag). It is like a SET except now we can add an item more that one time. If we add an item twice, then the count for that item is 2... it is in the MSET twice. The rem operation takes a single instance of an item from the mset; the removed item might still be in the mset (if it was in more than one time). When an item is in the mset one time, and is removed, it is no longer in the mset.

    The operations for MSET are: new, add, rem, card, and mem (like SET, but the semantics vary.
    new makes an empty MSET
    add as noted put an item into the MSET and you can add an item repeatedly, a count of how many instances are in the mset must be kept for every different item added
    rem takes one instance of an item out of the MSET
    card tells how many items are in the MSET (counting every instance of every item)
    mem (member) is not boolean in MSET... it returns an Int and tells how many times an item is in the MSET (0 means it is not in the MSET)

    Example:
    S: 2, 6, 6, 6, 9, 9, 12
    add 9 to S: 2, 6, 6, 6, 9, 9, 9, 12
    rem 6 from S: 2, 6, 6, 9, 9, 9, 12
    card of S: 7
    mem 6 in S: 2
    mem 12 in S: 1
    mem 10 in S: 0

In Sakai, Upload a zip file containing your ml source files. Also include in that a text file with the names of the group members, if you worked in a group.






Assignment 0: OO Issues

Prepare a single document (PDF, or Word) that contains your answers to this discussion question.
Then submit it in Sakai for Assignment 0 as a single PDF file.

Due: Sun. 9/3 9:00pm in Sakai

  1. Research OO models and languages; find objections to it as a programming technology, and issues that people are critical of.

    What are its failings and shortcomings?

    What we are after here is to have a list of issues so that -- as language designers -- we have guidance for developing new mechanisms to manage or alleviate these shortcomings.

    Note I want a discussion here, not simply a list of issues/phrases. For the objections and issues you find, explain each or give examples supporting the claims made about it.

Assignment 0.a: Teams

Due: Sun. 9/3 9:00pm in email

You are allowed to work together in teams of size 1, 2, or 3 this semester. So form teams and let me know the team compositions.

Send me email (to the class account) telling me the names of the students in your team.
If you are a team of 1, send me email as well saying so.
I want to make sure all names on our class roster are accounted for.