Docsity

COMP348 Post-Midterm Review: Python, Memory, Functional Programming, Exams of Nursing

Toggle sidebar
bg1
COMP348 - Post Midterm questions with
100% complete solutions
Does Python provide object-oriented programming? - correct answer ✔✔Yes
(Python) Object creation syntax - correct answer ✔✔my Foo = Foo()
(Python) What are the permissions associated with variables defined outside a class - correct answer
✔✔Can be accessed by any object of class. Essentially class variables.
(Python) What is the constructor for a class - correct answer ✔✔__init__
(Python) How to create local variables for a class object? - correct answer ✔✔Declare inside the
constructor as self.variable_name
(Python) How to call parent constructor? - correct answer ✔✔Parent_name.__init__(self)
(Python) What will class Foo (Baz) inherit? - correct answer ✔✔Methods and class variables
(Python) How to inherit instance variables from parent class? - correct answer ✔✔child __init__ must
call parent __init__
(Python) Can class/structure definitions be modified at run-time? - correct answer ✔✔Yes
(Python) How do you declare something as private/protected? - correct answer ✔✔Trick question. You
can't
(Python) What is the "convention" for indicating a variable is meant to be used privately? - correct
answer ✔✔preface variable name with leading underscore
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download COMP348 Post-Midterm Review: Python, Memory, Functional Programming and more Exams Nursing in PDF only on Docsity!

COMP348 - Post Midterm questions with

100% complete solutions

Does Python provide object-oriented programming? - correct answer ✔✔Yes (Python) Object creation syntax - correct answer ✔✔my Foo = Foo() (Python) What are the permissions associated with variables defined outside a class - correct answer ✔✔Can be accessed by any object of class. Essentially class variables. (Python) What is the constructor for a class - correct answer ✔✔init (Python) How to create local variables for a class object? - correct answer ✔✔Declare inside the constructor as self.variable_name (Python) How to call parent constructor? - correct answer ✔✔Parent_name.init(self) (Python) What will class Foo (Baz) inherit? - correct answer ✔✔Methods and class variables (Python) How to inherit instance variables from parent class? - correct answer ✔✔child init must call parent init (Python) Can class/structure definitions be modified at run-time? - correct answer ✔✔Yes (Python) How do you declare something as private/protected? - correct answer ✔✔Trick question. You can't (Python) What is the "convention" for indicating a variable is meant to be used privately? - correct answer ✔✔preface variable name with leading underscore

What happens if dynamic memory allocation is not reclaimed? - correct answer ✔✔Memory leak How does the "Mark and Sweep" algorithm work - correct answer ✔✔Start with the "root set" of live or active objects, consisting of global variables and variables/references on current call stack.

  1. Mark Phase: identify all reachable objects and set "in use" flag
  2. Sweep Phase: Cycle through all objects in heap and checks their flag. If flag is not set, object can now be reclaimed What strategies are used to invoke CG? - correct answer ✔✔-When determined that memory is low -On pre-defined schedule (less likely) What is the issue with the "Mark and Sweep" algorithm? - correct answer ✔✔Costly for large applications What is C's external GC called? - correct answer ✔✔Boehm GC Describe the Boehm GC - correct answer ✔✔1. Uses mark and sweep algorithm
  3. Black box: it is not integrated into the compiler
  4. Conservative: it will do its best to "guess" which objects can be reclaimed Replaces malloc calls with its own versions What happens when there is a Boehm GC false negative? - correct answer ✔✔"Transient" memory leak - it will eventually be resolved In what case is GC not typically used? - correct answer ✔✔Performance sensitive system coding What does Python use for GC? - correct answer ✔✔reference counting

What does REPL stand for? - correct answer ✔✔Read Evaluate Print Loop How to print in Clojure - correct answer ✔✔(println content) (Clojure) What does a print statement return? - correct answer ✔✔nil Variable types in Clojure - correct answer ✔✔Integer, Float, String, Boolean, nil (=NULL) (Clojure) Bind name to value - correct answer ✔✔(def name value) Values are ___ to current namespace - correct answer ✔✔local (Clojure) Trivial Function - correct answer ✔✔(fn [paramlist] body) (Clojure) Named Function - correct answer ✔✔(defn name [paramlist] body) (Clojure) Where is the return value of a function located? - correct answer ✔✔last line of the function (Clojure) If form - correct answer ✔✔(if boolean-form then-form optional-else-form) (Clojure) What does Do do? (lol) - correct answer ✔✔allows a sequence of expressions to be defined in an if statement (Clojure) What does When do? - correct answer ✔✔combines if-do (Clojure) What are falsey values? - correct answer ✔✔nil and false (Clojure) What are truthy values - correct answer ✔✔everything except nil and false

(Clojure) What are the types of composite data structures? - correct answer ✔✔map, vector, list, set (Clojure) Map declaration - correct answer ✔✔-{"John" "professor" "Sue" "doctor" "Ahmed" "astronaut"}

  • Keyword definition: {:john "professor" :sue "doctor" :ahmed "astronaut"} (Clojure) What is the Python equivalent of a map? - correct answer ✔✔Dictionary (Clojure) What is a vector? - correct answer ✔✔0-indexed array (Clojure) List declaration - correct answer ✔✔'(1 2 3) or (list 1 2 3) (Clojure) Vector declaration - correct answer ✔✔[1 2 3] or (vector 1 2 3) (Clojure) Which data structure has unique values? - correct answer ✔✔Sets (Clojure) Set declaration - correct answer ✔✔#{1 2 3} or (set 1 2 3) (Clojure) Which data structures use (get name index) - correct answer ✔✔vectors, lists (Clojure) Which data structures use (nth name index) - correct answer ✔✔Lists (Clojure) Which data structures use word lookup - correct answer ✔✔maps, sets (Clojure) How to add documentation? - correct answer ✔✔; or doc strings just after defn line (Clojure) Display documentation for a function - correct answer ✔✔(doc myFunc) (Clojure) How to do arity overloading? - correct answer ✔✔( defn func_name

(require [test.bar :as bar]) or (:require [test.bar :as bar :refer myFunc])) When was Erlang developed? - correct answer ✔✔1980s-1990s What relevant framework is based on the Erlang language? - correct answer ✔✔Akka concurrency framework How does Erlang run? - correct answer ✔✔Runs on top of BEAM virtual machine, run through command line shell Eshell (Erlang) What basic data types are there? - correct answer ✔✔int, float, strings What notation does Erlang use for expressions? - correct answer ✔✔infix (Erlang) Variables can only be assigned ___ and begin with what? - correct answer ✔✔once, begin with an uppercase letter (Erlang) When is a comma used? - correct answer ✔✔between function arguments and expressions in a function body (Erlang) When is a semi-colon used? - correct answer ✔✔between alternate forms or arities of a function (Erlang) When is a period used? - correct answer ✔✔terminate a complete expression (Erlang) What are the composite data types? - correct answer ✔✔Tuple, Lists, Records, Maps (Erlang) How to define a tuple? - correct answer ✔✔{person, "John Smith", 43}

{person, "John Smith", 43} {person, _ , Age What is Age now? - correct answer ✔✔ 43 (Erlang) How to define a list? - correct answer ✔✔[13, 25, {person, "john", 43}] (Erlang) What is the head and tail of a list - correct answer ✔✔head: first element tail: everything else (Erlang) What is a record? - correct answer ✔✔like a tuple but has labels associated with values (Erlang) How to declare a record? - correct answer ✔✔-record (name, { key1=val1, key2=val2, ... key3, ... }). (Erlang) How to import a record? - correct answer ✔✔-include("person.hrl"). (Erlang) How to declare a map? - correct answer ✔✔M1 = #{man => "joe", woman => "sue") (Erlang) How to declare a function? - correct answer ✔✔func_name (parm1, parm2, ...parmN) -> expression_1, expression_2, ... expression_N.

What are critical regions? - correct answer ✔✔block of code in which an update to shared data is made (Concurrency) What is a lock? - correct answer ✔✔variable that can be set to open/closed What is the modern CPU "test and swap" instruction? - correct answer ✔✔"wrapper" function for this instruction so language libraries can provide reliable application locks (Concurrency) Deadlock - correct answer ✔✔thread A is waiting for a lock held by thread B while thread B is waiting on a lock held by thread A (application spends forever in this state) (Concurrency) Livelock - correct answer ✔✔threads spend a lot of time releasing locks to make them available for the other but in the meantime don't get much work done Message passing is ____, and it appends the message to the ____ which can be ____ at any time - correct answer ✔✔Message passing is asynchronous, simply appends the message to the queue which can be checked at any time (Erlang) What are the three elements of message passing? - correct answer ✔✔send, spawn, receive (Erlang) Spawn function syntax - correct answer ✔✔Pid = spawn (Mod, Func, Args) (Erlang) Send function syntax - correct answer ✔✔Pid! Message (Erlang) Receive function syntax? How does it work? - correct answer ✔✔listen() -> receive {dog, Name} -> "Mr" ++ Name; {cat, Name} -> "Ms" ++ Name end. recieve function that includes one or more patterns that can be matched against the message(s) that arrive in the process queue

(Erlang) What happens if a message is received but no match is found? - correct answer ✔✔message goes into "save" queue and can be checked again later (Erlang) How to do two-way communication? - correct answer ✔✔include the sender's process ID with the message so the sender can send a message back (Clojure) What are the reference data types? What do they do? - correct answer ✔✔atoms, agents, refs. They allow mutable state to be changed in a safe manner (Clojure) What is a Future? - correct answer ✔✔block of code that Clojure will schedule and run in a separate thread (Clojure) What is special about an Atom? - correct answer ✔✔modification is guaranteed to complete before any other process can access/update the same value. It is a BLOCKING operation. (Clojure) How to change value in an Atom? - correct answer ✔✔(swap! Atom update_function) or (reset! Atom new_value) (Clojure) What is an Agent? - correct answer ✔✔atomic references that are set and dereferenced with standard syntax but they are NON BLOCKING (Clojure) What is a transaction? - correct answer ✔✔set of related operations (multiple update queries processed simultaneously) (Closure) What is software transactional memory - correct answer ✔✔A concept borrowed from transactions. Defines a set of updates that must be performed atomically. Logically, this is a critical region protected by a lock. (Clojure) STM uses ____ protocol and what does it mean? - correct answer ✔✔· Uses optimistic protocol. Transactions do not wait to obtain a lock. Proceed directly, preform updates, and then when they are ready to commit, Clojure checks if any of their reference values have changed since the transaction began.